[BangPypers] ElementTree nodes
sidharth.kuruvila at gmail.com
Sun Oct 25 21:50:30 CET 2009
Ah yes, silly me. Must remember to go to the docs before posting :">.
On Mon, Oct 26, 2009 at 2:12 AM, bhaskar jain
<bhaskar.jain2002 at gmail.com> wrote:
> On Mon, Oct 26, 2009 at 1:53 AM, Sidharth Kuruvila <
> sidharth.kuruvila at gmail.com> wrote:
>>>>It turns out any object that returns len(o) as 0
>>>>will evaluate as false.
> Not always.
> doc says - "instances of user-defined classes, if the class defines a
> __nonzero__() or __len__() method, when that method returns the integer zero
> or bool value False."
> Called to implement truth value testing and the built-in operation bool();
> should return False or True, or their integer equivalents 0 or 1. When this
> method is not defined, __len__() is called, if it is defined, and the object
> is considered true if its result is nonzero. If a class defines neither
> __len__() nor __nonzero__(), all its instances are considered true.
> First it looks for __nonzero__ and if its absent then only __len__
>>>> class c:
> ... def __nonzero__(self):
> ... return False
> ... def __len__(self):
> ... return True
>>>> o = c()
> BangPypers mailing list
> BangPypers at python.org
I am but a man.
More information about the BangPypers