[BangPypers] ElementTree object instance evaluates to False?

Vikas BN vikas.bn at gmail.com
Tue Dec 6 05:35:23 CET 2011


Hi Navin,

On Tue, Dec 6, 2011 at 9:54 AM, Navin Kabra <navin.kabra at gmail.com> wrote:
> 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
>
> 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
          Thanks! That's it I think.

>>> c1.__len__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __len__
>>> len(c1)
0

         So len(c1) is returning 0. But I don't undestand why __len__
is throwing an AttributeError. Time to read ElementTree docs I
suppose.

Thanks!
Vikas


More information about the BangPypers mailing list