True/False

Roy Smith roy at panix.com
Tue Apr 22 18:28:37 EDT 2003


In article <mailman.1051036237.30103.python-list at python.org>,
 Ian Bicking <ianb at colorstudy.com> wrote:

> import sys
> if sys.version_info < (2, 3):
>     True, False = 1==1, 0==1

If you insisted on doing something like that, you'd be a bit more 
portable making the test "'True' not in dir(sys)".  I think it would 
also be a lot easier to read if you broke the assignment up into two 
simplier statements:

import sys
if 'True' not in dir(sys):
   True = 1
   False = 0

I'm not 100% sure testing for the presense of 'True' in dir(sys) is the 
right test, but it's better than testing for an absolute version number.
  
A better test might be looking for 'BoolType' in dir(types), or testing 
for the presense of True in the global namespace by evaluating it inside 
a try block and catching NameError.  Or something.  The basic idea is to 
test for the functionality you're looking for, not a version number.




More information about the Python-list mailing list