python 2.5 and ast

Andrea Crotti andrea.crotti.0 at gmail.com
Tue Nov 29 08:51:26 EST 2011


On 11/29/2011 11:32 AM, Steven D'Aprano wrote:
>
> I prefer to check against sys.version.
>
> import sys
> if sys.version<= '2.5':
>      from psi.devsonly.ast import parse, NodeVisitor
> else:
>      from ast import parse, NodeVisitor
>
>
>
> Or even:
>
>
> try:
>      from ast import parse, NodeVisitor
> except ImportError:
>      from ast import parse, NodeVisitor
>
>
>

The try/except is probably the nicest...
I've seen in other places using sys.version <=, but is it a good idea to 
rely
on the fact that the <= on strings has the right semantic?
After all that's just a string, version_info looks more correct to me..



More information about the Python-list mailing list