Strange result ffor object to bool

Z

ZhouPeng

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
 
S

Steven D'Aprano

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top