Sergey Kishchenko wrote:
In Python empty container equals False in 'if' statements:
# prints "It's ok"
if not []:
    print "It's ok"

Let's create a simple Foo class:

class Foo:
    pass

Now I can use Foo objects in 'if' statements:

#prints "Ouch!"
f=Foo()
if f:
    print "Ouch!"

So, default __nonzero__ impl is to return True. I think, this
behaviour conflicts with 'Explicit is better than implicit' and
'Practicality beats purity' statements. I think, throwing a TypeError
exception would be better.  It will result in more explicit code with
fewer errors.
Sensible (and documented) defaults pervade Python.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to