A bit weird dictionary behavior

Terry Reedy tjreedy at udel.edu
Tue Sep 23 01:29:38 CEST 2008


Grzegorz Staniak wrote:
> On 22.09.2008, Carl Banks <pavlovevidence at gmail.com> wroted:

>>> Some would argue (and some did by the time Python grew a 'bool' type)
>>> that what is wrong is to have a bool type in a language that already
>>> have a wider definition of the truth value of an expression...
>> And some would argue that it was wrong to have such a wide definition
>> for the truth value of an expression in the first place...

An alternate viewpoint is that only True and False 'have' a truth value. 
  So whenever the interpreter *needs* a truth value for conditional and 
logical operations, and it has something else, it implicitly calls 
bool(ob) to get one.  This, or possibly a shortcut version thereof, is 
what a Python interpreter effectively does.

 From this viewpoint, objecters would instead have to argue that it is 
wrong to have such implicit calls and that programmers should have to 
put them in explicitly.

> Just out of idle curiosity, what could be the alternatives? Not to evaluate 
> e.g. strings to "true"? Aren't such conventions as "whatever is not empty,
> is 'true'" popular in dynamic langauges?

I do not know what is popular, but implicit bool call are darn handy.

tjr




More information about the Python-list mailing list