Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python XML parsing missing element: 'None' vs None

I am parsing an XML file and trying to find some XML tags. I’m looking for the tag personalDataRelated and when running it depending on XML file, I either get one of the two values below :

<Element 'personalDataRelated' at 0x0000020417C86AC0>
None

What I do next is depending on the value I get previously my variable data gets a special value attributed, but it doesn’t work, and even if I get None, it doesn’t set data as Non

import xml.etree.ElementTree as et

xmlfileName = 'new.xml'
xmlparse = et.parse(xmlfileName)
root = xmlparse.getroot()

print(root.find('personalDataRelated'))
if root.find('personalDataRelated') != 'None':
    data = "Oui"
else:
    data = "Non"

What am I doing wrong ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re testing against the 'None' string when you should be testing against the None keyword.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading