[FRPythoneers] Python documentation and default expression

Rob Riggs rob at pangalactic.org
Fri Mar 15 15:28:25 MST 2002


Mike Olson wrote:

>http://www.python.org/doc/current/lib/truth.html
>
This was the most concise reference. Thanks.

>>Along the same lines, what are the thoughts on using this type of test 
>>in code? The reason I ask is that I was just burned on a test like this 
>>when I extended a class to include a __len__() member function. What I 
>>really wanted to test was that the class wasn't "None", and using the 
>>above idiom worked well for that. At least it did until I added __len__().
>>
>
>You should use what you really wanted to test.  In the above, you said
>you wanted to see if foo is None so that should be your test.  With
>python, you'll get all sorts of weird errors popping up other wise.
>
As I've just discovered. I think I will be much more careful about this 
in the future.

If it doesn't do so already, this sounds like it could be a valuable 
test in PyChecker.

> 
>also, if your counting clock cycles, 
>
>if foo is not None:
>
>will actually be quicker.
>
I've almost always used "if foo != None:". Is there a reason not to 
write it as such?

-Rob




More information about the FRPythoneers mailing list