Python code for 2.5 and 2.4?

Mike Driscoll kyosohma at gmail.com
Mon Feb 25 17:08:23 EST 2008


Joseph,

On 2/25/08, Joseph Turian <turian at gmail.com> wrote:
>
>  > Seehttp://docs.python.org/lib/built-in-funcs.htmlwhich shows the
>  > current built-ins for Python. It also shows an equivalent function for
>  > all() that should work in 2.4.
>
>  Yes, I see that.
>
>  > You can do a check at the beginning of your file by importing the sys
>  > module. Something like this:
>  > <code>
>  > # untested
>  > import sys
>  > version = sys.version.split(' ')[0]
>  >
>  > if '2.5' not in version:
>  >    # use custom all() script
>  >
>  > </code>
>
>  Okay.
>  I guess I was asking how do I nicely package the above into a file
>  python25.py from which I can do:
>   from python25 import all
>  And python25 figures out the python version and returns either the
>  hand-coded version or the library version.
>  How can I write python25.py ?
>

Well one way to do this would be something like this:

<python25.py>

def all(iterable):
         for element in iterable:
             if not element:
                 return False
         return True

</python25.py>

And combine that with the code that Robert gave you. I'm not sure of
the exact syntax, but I would think you could do an IF statement that
creates the custom definition and returns it if Python 2.4 or less is
installed and return the normal version for 2.5 if it is installed.

Mike



More information about the Python-list mailing list