12

我需要检查某些属性是否存在。喜欢:

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

1 回答 1

31

Elementattrib对象具有字典中的所有属性。

if 'blah' not in elem.attrib:
   print "there is no such attribute"
于 2012-06-21T15:30:00.230 回答