[BangPypers] ElementTree object instance evaluates to False?

Navin Kabra navin.kabra at gmail.com
Tue Dec 6 05:24:32 CET 2011

On Tue, Dec 6, 2011 at 9:49 AM, Vikas BN <vikas.bn at gmail.com> wrote:
>    I'm working on a script to parse XML files and am using
> cElementTree for the same. However,
>    I was under the impression that anything that's a None type or 0 or
> "" would evaluate to False
>    and the rest would be True (incl an instance of an object).

Any object that has a __len__ defined will evaulate to False in a
boolean context if __len__ returns 0. (See also __nonzero__).

See section 5.1 here: http://docs.python.org/library/stdtypes.html

I hope this answers your question.

More information about the BangPypers mailing list