bool and unicode
Raymond Hettinger
vze4rx4y at verizon.net
Tue Aug 26 12:19:21 EDT 2003
[Roman Yakovenko]
> But still I expect this code to work.
>
> assert False == bool( str( bool( False ) ) )
>
> The context of previous expression is in serialization.
It would be more reasonable to expect:
assert False == bool(eval(repr(False)))
The code you listed does work for int, complex, long, and float,
but does not generalize to other types:
>>> int('2')
2
>>> complex('3+4j')
(3+4j)
>>> long('3L')
3L
>>> float('3.14')
3.1400000000000001
>>> list('[1,2]') # this won't work
['[', '1', ',', '2', ']']
>>> tuple('(1,2)') # neither will this
('(', '1', ',', '2', ')')
Raymond Hettinger
More information about the Python-list
mailing list