question about True values

Antoon Pardon apardon at forel.vub.ac.be
Fri Oct 27 06:09:27 EDT 2006


On 2006-10-26, Steve Holden <steve at holdenweb.com> wrote:
> John Coleman wrote:

>> As far as using non-booleans as conditions - I just think that if you
>> want a certain block of code to be executed only if, for example, a
>> list is non-empty, why not *say* so? I think "if my_list != []:" just
>> reads better than "if my_list:". I would think that my preferences
>> there mesh with "Explicit is better than implicit" but apparently not.
>> 
> Maybe so, but that "rule" (and let's not forget that the zen is not 
> actually a set of prescriptive rules but rather guidelines for the 
> informed) is immediately preceded by the most important "rule" of all: 
> "Beautiful is better than ugly". Nobody will shout at you (well, 
> hopefully, not on this list they won't) for writing
>
>    if my_list != []:
>      ...

That depends on what you consider as shouting. My impression is that
if people come here with a problem and post a sample of code to
illustrate. That if that code would contain something like the above
about half of the responses will be about the code not following
python idiom without further providing anything helpfull with the actual
problem. Now you may not consider that as shouting but I guess it
can be just as intimidating.

>> 
> It probably will, but I wouldn't get too hung up on what's definitely a 
> small point. Enjoy Python the way it is, and the way you are. You and 
> Python will definitely come to an accommodation (and you will love the 
> combination of discipline and freedom that it brings to programming 
> style). Welcome to the language!

I'll second that. Python has it warts, but so has any language.
Chances are John will find the warts of python are minor
issues compared with other languages.

-- 
Antoon Pardon



More information about the Python-list mailing list