bool and unicode

Roman Yakovenko romany at actimize.com
Tue Aug 26 04:30:55 EDT 2003


Thanks. I am going to sleep a little :-).

But still I expect this code to work.

assert False == bool( str( bool( False ) ) )

The context of previous expression is in serialization.

I save\read my data in\from XML file. So I expected this to work
without any additional afford from me. But I was wrong.
My mistake was exectly as you explain, thanks.

Roman

> -----Original Message-----
> From: Erik Max Francis [mailto:max at alcyone.com]
> Sent: Tuesday, August 26, 2003 9:12 AM
> To: python-list at python.org
> Subject: Re: bool and unicode
> 
> 
> Roman Yakovenko wrote:
> 
> > Hi.
> > 
> > >>> bool( u'True' )
> > True
> > >>> bool( u'False' )
> > True
> > >>>
> > 
> > May somebody explain or give a reference to reason of such 
> behaviour?
> 
> Does this give you a hint?
> 
> >>> bool('True')
> True
> >>> bool('False')
> True
> >>> bool('')
> False
> 
> The only string, Unicode or not, considered to be false is the null
> string.  All other strings are true, even if they spell the word
> _false_.
> 
> -- 
>    Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
>  __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
> /  \ Procrastination is the thief of time.
> \__/  Edward Young
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list