Python version dilemma
Aahz Maruch
aahz at panix.com
Mon Aug 27 16:20:30 EDT 2001
In article <mailman.998941722.3618.python-list at python.org>,
Skip Montanaro <skip at pobox.com> wrote:
>
> > I have a set of scripts that use 2.1 syntax. Now, I'd really like
> > these scripts to, when run by the 1.5 interpreter, gracefully state
> > that version 2 is required. However, my code fails during the
> > compilation stage with the 1.5 interpreter (SyntaxError's and such),
> > and so never gets the chanced to execute a code portion that might
> > print a pretty (or at least useful) error message.
>
>What you might want to do is push your version dependent code into separate
>modules. Suppose your module is named "mod". In mod.py do this:
>
> try:
> from mod21 import *
> except SyntaxError:
> from mod15 import *
Eww. That would mask a real syntax error (say, introduced by a typo).
Use an if statement.
--
--- Aahz <*> (Copyright 2001 by aahz at pobox.com)
Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista
"Plus ca change, plus c'est la meme chose."
More information about the Python-list
mailing list