Python style guidelines
Josef Meile
jmeile at hotmail.com
Thu Mar 11 04:48:35 EST 2004
> Is there something missing you think should be there? There's no particular
> reason a PEP needs to be continually updated. In particular, notions of
> good Python style haven't changed a lot over the past ten years.
>
> Skip
I agree, those are good guidelines, but I don't agree with:
- Don't compare boolean values to True or False using == (bool
types are new in Python 2.3):
No: if greeting == True:
Yes: if greeting:
What would happened if you do:
>>> a='test'
>>> if a.find('foo'):
... print "foo was found"
...
foo was found
I think you should never do a direct boolean comparison. Instead
one should use a more elaborate boolean expresion like:
>>> a='test'
>>> if a.find('foo') >= 0:
... print "foo was found"
...
You will have problems specially if you come from languages where
values minor than zero are considered to be false. I think the
previous sintax is ambiguous.
Regards,
Josef
More information about the Python-list
mailing list