graceful version detection?
Paul Prescod
paulp at ActiveState.com
Sun Jun 17 19:02:41 EDT 2001
Ben Collins-Sussman wrote:
>
> Please excuse me if this is a common newbie question; I didn't find it
> in the FAQ or tutorial.
>
> If I write a python script that uses 2.X features, and then run it with
> a 1.X interpreter, I get a bunch of exceptions. Presumably this happens
> during the initial byte-compilation.
>
> I'd like the script to instead gracefully print:
>
> "Sorry, this program requires Python 2.0 or higher."
I don't have a 1.x parser around to try this but I'm pretty confident of
it. If it works, maybe you could submit it to the Python cookbook.
Move your real code to a module ("let's call it 'main'")
Then make a "driver" program that users invoke:
try:
import main
except SyntaxError:
print "This program requires Python 2.0"
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list
mailing list