Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Is there a boolean(somestring) equivalent of int(somestring).bool('false') -> True

Reply
Thread Tools

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

 
 
Paul Prescod
Guest
Posts: n/a
 
      04-12-2004
Vineet Jain wrote:

> Thanks for the code suggestion.
>
> From what I've read, most people (including me) are attracted to Python
> because of how natural it is. Give that is a high priority for the language
> designers:
>
> How can anyone argue that
>
> bool('false') = True
>
> is more natural (and what you would expect) than
>
> bool('false') = False


For most (all?) built-in types there is one and only one false value. If
you start to accept multiple false values then you run into the types of
problems Perl programmers run into. You write code like this:

a = input()
if a:
...
else:
...

And knowing what it does requires you to keep in mind ALL of the false
values for the type. So you test your program with one dataset and one
day another of the false values pops up and your program behaves
incorrectly. Python's rule is simpler.

> Having just got over the surprise that int('2.1') fails while
> int(float('2.1')) works the above surprises me even more. If the int case
> was rejected because it is 'better to be explicit than not' then how can you
> bool('false') be allowed??


"false" is just a random English word. The Python builtin is called
"False".

> Booleans are associated with (True, on, 1 and yes) and bool() on any them
> should return True.


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. If Python started
guessing what strings are vaguely affirmative, people would always
"expect" it to read their minds just a little bit more effectively than
it does. The current rule is very simple: the empty string is false. All
others are true. It is trivially easy for you to redefine conversion to
boolean for any particular data set:

def mybool():
return mystring=="oui"

Paul Prescod



 
Reply With Quote
 
 
 
 
Joe Mason
Guest
Posts: n/a
 
      04-12-2004
In article <mailman.536.1081742734.20120.python->, 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. If Python started


UniConf

http://open.nit.ca/wiki/?page=UniConf

(The current list is "true", "yes", "on", and "enabled" evaluate to 1,
"false", "no", "off", and "disabled" to 0, anything else is passed
through strtol. This is specifically a configuration system, where it
makes sense to be forgiving in what you accept, but you did ask for a
language *or system*.)

Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
C and C++ are interoperable languages? True or Not True? Chip C++ 6 01-08-2005 11:10 PM
Does true ^ true return false? Siemel Naran C++ 19 06-18-2004 11:06 AM
RE: Is there a boolean(somestring) equivalent of int(somestring).bool('false') -> True Vineet Jain Python 2 04-12-2004 03:00 PM
CSS equivalent of <td nowrap="true"/> ? Joshua Beall HTML 20 02-24-2004 06:20 PM



Advertisments