my code only loops once then return only one data. below is my code
def test():
for element_regFile in root.findall('country'):
csvdataElement=[]
filename=element_regFile.find('name')
if filename != None:
filename=filename.text
else:
filename='None'
csvdataElement.append(filename)
return csvdataElement
Then, i want to print the output of the function one by one as shown below:
print test()
>>>> [London]
>>>> [Paris]
The print statement will be outside the function
Below is my xml:
?xml version="1.0"?>
<data>
<country >
<name>London</name>
<rank>1</rank>
<abc>123</abc>
<year>2008</year>
<gdppc>141100</gdppc>
</country>
<country >
<name>Paris</name>
<rank>1</rank>
<year>2010</year>
<gdppc>68000</gdppc>
</country>
</data>
It should return London and Paris. But unfortunately, it only return London.