Is there a boolean(somestring) equivalent of int(somestring). bool('false') -> True

Jeff Epler jepler at unpythonic.net
Mon Apr 12 10:10:37 EDT 2004


On Sun, Apr 11, 2004 at 09:01:59PM -0700, Paul Prescod wrote:
> Maybe in your mind. What about "true", "TRUE", "oui", "1.0", "positive" 
> and "yeah". How far do you intend to go? Name a single language or 
> system that treats "True", "on", "1" and "yes" as positive values and 
> "False", "off", "0" and "no" as negative values.

Tcl is pretty liberal:
       Tcl_GetBoolean expects string to specify a boolean value.  If string is
       any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at
       *boolPtr.  If string is any of 1, true, yes, or on, then 1 is stored at
       *boolPtr.   Any  of  these  values  may  be abbreviated, and upper-case
       spellings are also acceptable.
Tcl_GetBoolean is used when configuring widgets (text .t -exportselection
tRuE) but not in mathematical expressions ([expr false]).  Personally, I
think this rule is crazy, and I try to use (the strings) "0" and
"1" as boolean values, since they work in expressions and as widget
configuration parameters.

Jeff




More information about the Python-list mailing list