hex/oct constants > sys.maxint will return positive values in Python 2.4 and up

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Nov 7 17:38:20 EST 2002


Jon Ribbens fed this fish to the penguins on Thursday 07 November 2002 
09:12 am:


> But that *won't work* on later versions of Python! It means I will
> have a line in my code which I know will suddenly stop working at some
> point in the future and I will have to make a new release and everyone
> will have to upgrade their copies of my module just because I put in
> code which I knew wasn't going to work.

        Well, can't you make use of something like sys.version_info to 
determine which version you are running under, and use the form of 
assignment appropriate to that version when defining your constant?

import sys

pver = sys.version_info

if pver[0] == 2:        #2.x line
        if pver[1] == 2:        #2.2
                do assignment
        elif pver[2] == 3:      #2.3 expected
                do assignment
...

        Might need to store the assignments as strings, and do an eval/exec 
type operation on just the correct string if Python tries to interpret 
the assignments in false branches...

-- 
--  
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list