标签: python xml elementtree
我需要检查存在的某些属性。像:
if "blah-blah-blah" is None: print "there is no such attribute" else: print "The attribute exists"
答案 0 :(得分:16)
Element个对象拥有attrib词典中的所有属性。
Element
attrib
if 'blah' not in elem.attrib: print "there is no such attribute"