Neal Becker wrote:
Instead, bool fails in _the worst possible way_: it silently gives a _wrong result_.

I disagree with the word "fail" there; Python is working correctly. The behavior of converting expressions to a boolean is well-defined:
   http://docs.python.org/ref/Booleans.html
Perhaps the behavior is unexpected or unwelcome--but it is *correct*. It's just one of those things about Python that one has to get used to; this is a side-effect of another, much more important principle.

If you really want to turn the string "True" into True, use "eval".
   eval("4") -> 4
   eval("True") -> True
   eval("{}") -> {}
Perhaps it would be safest to cast the output of eval to bool:
   bool(eval("True")) -> True
   bool(eval("")) -> False


Cheers,

/larry/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to