dd
Size: a a a
dd
dd
dd
A
OO
OB
def xml_df(city, path):
path = path + city + '.xml'
dfcols = ['id', 'name' ,'available', 'price','dimensions']
root = et.parse(path)
rows = root.findall('.//offer')
xml_data = [[row.get('id'), row.find('name').text, row.get('available'), row.find('price').text, row.find('dimensions').text] for row in rows]
df_xml = pd.DataFrame(xml_data, columns=dfcols)
return df_xml
'dimensions'
AttributeError: 'NoneType' object has no attribute 'text'
АМ
def xml_df(city, path):
path = path + city + '.xml'
dfcols = ['id', 'name' ,'available', 'price','dimensions']
root = et.parse(path)
rows = root.findall('.//offer')
xml_data = [[row.get('id'), row.find('name').text, row.get('available'), row.find('price').text, row.find('dimensions').text] for row in rows]
df_xml = pd.DataFrame(xml_data, columns=dfcols)
return df_xml
'dimensions'
AttributeError: 'NoneType' object has no attribute 'text'
.get('text')
?АМ
M🌗
def xml_df(city, path):
path = path + city + '.xml'
dfcols = ['id', 'name' ,'available', 'price','dimensions']
root = et.parse(path)
rows = root.findall('.//offer')
xml_data = [[row.get('id'), row.find('name').text, row.get('available'), row.find('price').text, row.find('dimensions').text] for row in rows]
df_xml = pd.DataFrame(xml_data, columns=dfcols)
return df_xml
'dimensions'
AttributeError: 'NoneType' object has no attribute 'text'
M🌗
YP
YP
xml_data = [[row.get('id'), row.find('name').text, row.get('available'), row.find('price').text, row.find('dimensions').text or ''] for row in rows]
YP
row.find('dimensions').text
AK
YP
or ''гораздо проще, чем отлавливать экзепшн, разве нет?
AP
AK
OB
xml_data = [[row.get('id'), row.find('name').text, row.get('available'), row.find('price').text, row.find('dimensions').text or ''] for row in rows]
YP
YP