user1464922
user1464922

Reputation: 381

How can I check attribute existings by Elementtree?

I need to check certain attributes for existence. Like:

if "blah-blah-blah" is None:
    print "there is no such attribute"
else:
    print "The attribute exists"

Upvotes: 14

Views: 20041

Answers (1)

Lev Levitsky
Lev Levitsky

Reputation: 65851

Element objects have all the attributes in the attrib dict.

if 'blah' not in elem.attrib:
   print "there is no such attribute"

Upvotes: 37

Related Questions