1 or 1/0 doesn't raise an exception

r rt8396 at gmail.com
Sun Dec 14 01:24:42 EST 2008


> Let me just point out that unsuspecting people (like me) might rely on
> the whole expression to be evaluated and rely on exceptions being
> raised if needed.

This happens when people assume something ;)
Use a different construct if you want to catch error's, I don't
understand how you could not get it?

>>> bool(1)
True
>>> bool(0)
False
>>> bool([])
False
>>> bool([0])
True
>>> bool([0,0,0])
True
>>> bool({})
False
>>> bool(())
False
see a pattern here?
>>> [] or {} or () or 0 or 1
1
>>> bool('python rules!')
True



More information about the Python-list mailing list