elementtree behavior

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Sep 27 15:12:34 EDT 2004


"Tim Arnold" <tiarno at sas.com> wrote in message
news:cj9j8m$jn4$1 at license1.unx.sas.com...
> I have an XML snippet that I parse with ElementTree, and I get an element
> called self.makeToc
>
> Now this code:
>
>         print self.makeToc
>         if self.makeToc != None:
>             print 'here'
>             if self.makeToc: print 'but not here'
>
> gives this result:
> <Element toc at 40197e88>
> here
>
> Clearly self.makeToc has a value, so why isn't "if self.makeToc"  True?
> That is, if self.makeToc isn't None, why don't I get past 'if
self.makeToc'
>
> Can someone point out what am I not understanding?
>
> thanks,
> --Tim
>
Not sure about your XML Element classes, but a number of Python objects will
evaluate to false even if not set to None:
- boolean with value of 'false'
- integer with value of 0
- list with no elements

Perhaps your Element class evaluates to false if it has no child nodes, or
some similar thing.

-- Paul





More information about the Python-list mailing list