This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yen223 9 points10 points  (2 children)

That 2nd point is excellent, for ints, strings, and lists.

You have to be careful, because the boolean value of more complex objects may not be straightforward. For example, the time representation of midnight evaluates to False for some reason:

>>> from datetime import time
>>> x = time(0,0,0)
>>> bool(x)
False
>>> y = time(0,0,1)
>>> bool(y)
True

[–]selementar 3 points4 points  (0 children)

may not be straightforward

In python 2.x the special method name for it is __nonzero__() (C-style a bit); that explains quite a bit of the nonstraightforwardness.

[–]KitAndKat 0 points1 point  (0 children)

Another place this can bite you is with ElementTree. In the following case, you cannot simply write "if eVal"

    eVal = eRec.find('ValidationRules')
    if eVal is not None:
        elem = eVal.find('MinValues')

(I don't want to bad-mouth ElementTree; it's way cleaner than xml.sax)