[FRPythoneers] Python documentation and default expression

Mike Olson Mike.Olson at fourthought.com
Fri Mar 15 15:10:44 MST 2002

On Fri, 2002-03-15 at 14:39, Rob Riggs wrote:
> Where do I find Pythons rules for the default tests on a variable? I.e., 
> when I have an expressions like:
>     if foo: ...
> what are the tests on "foo" that are performed? Is this documented in 
> the language reference anywhere?


> 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. 
also, if your counting clock cycles, 

if foo is not None:

will actually be quicker.


> -Rob
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
Mike Olson                                Principal Consultant
mike.olson at fourthought.com                +1 303 583 9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
4735 East Walnut St,                      http://4Suite.org
Boulder, CO 80301-2537, USA
XML strategy, XML tools, knowledge management

More information about the FRPythoneers mailing list