Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16202 > unrolled thread

Strange result ffor object to bool

Started byZhouPeng <zpengxen@gmail.com>
First post2011-11-25 14:52 +0800
Last post2011-11-25 08:59 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Strange result ffor object to bool ZhouPeng <zpengxen@gmail.com> - 2011-11-25 14:52 +0800
    Re: Strange result ffor object to bool Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-25 08:59 +0000

#16202 — Strange result ffor object to bool

FromZhouPeng <zpengxen@gmail.com>
Date2011-11-25 14:52 +0800
SubjectStrange result ffor object to bool
Message-ID<mailman.3026.1322203948.27778.python-list@python.org>
Hi all,

In my program, I get a listen element by
listen = graphics.find("listen")

print listen is <Element listen at 6afc20>
print type listen is <type 'instance'>
I am sure listen is not None and can be accessed properly.

But print bool(listen) is False
if not listen  is True

-- 
Zhou Peng

[toc] | [next] | [standalone]


#16207

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-11-25 08:59 +0000
Message-ID<4ecf58fd$0$29988$c3e8da3$5496439d@news.astraweb.com>
In reply to#16202
On Fri, 25 Nov 2011 14:52:25 +0800, ZhouPeng wrote:

> Hi all,
> 
> In my program, I get a listen element by listen =
> graphics.find("listen")

What is a listen element? It is not a standard Python object. What 
library is it from?


> print listen is <Element listen at 6afc20> print type listen is <type
> 'instance'> I am sure listen is not None and can be accessed properly.
> 
> But print bool(listen) is False

What makes you think this is a strange result? Many things are false:

py> for obj in (None, [], {}, 0, 0.0, "", 42):
...     print bool(obj),
... 
False False False False False False True


-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web