True

Daniel Klein danielk at aracnet.com
Thu Aug 7 08:39:18 EDT 2003


On Wed, 06 Aug 2003 12:18:45 -0400, Peter Hansen <peter at engcorp.com>
wrote:

>> The reason I'm taking a str()  value is cuz it is being sent over a
>> socket to a non-python server process, where it is converted back to a
>> boolean.
>
>In that case, you'd be better off converting using your own routine
>rather than relying on a particular behaviour of str() for this test.
>Basically, do something like 
>
>def boolean2String(boolVal):
>  return { False : '1', True : '0' } [ not boolVal ]
>
>and save yourself any further future pain...

Thanks Peter, that will do the trick. Just  wondering though why you
chose to code the opposite values and not as

def boolean2String(boolVal):
    return {True:'1', False:'0'}[boolVal]

Dan




More information about the Python-list mailing list