How to get a boolean out of python minidom



This made me sad:



me@here ~
$ python
Python 2.7.8 (default, Oct 20 2014, 09:44:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> b=False
>>> b
False
>>> str(b)
'False'
>>> s=str(b)
>>> s
'False'
>>> b=bool(s)
>>> b
True
>>>


So, how do I get a boolean value from a xml document using the minidom? getAttribute gives me a string and I could always do:



attr = el.getAttribute( 'bodacious' )
if attr in [ '1', 'true', 'True', 'TRUE', 'y', 'Y', 'yes', 'Yes', 'YES' ]:
return True # a bodacious element
else:
return False # a most non-bodacious element


but it seems quite arbitrary. Is there a better way?


No comments:

Post a Comment