graceful version detection?

Rainer Deyke root at rainerdeyke.com
Sun Jun 17 18:38:42 EDT 2001


"Ben Collins-Sussman" <sussman at red-bean.com> wrote in message
news:3B2D2F44.50007 at red-bean.com...
> 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.

> What's the correct solution?

There is probably no elegant solution, but the following ugly hack should do
what you want:

import sys
if sys.version_info[0] < 2:
  print 'This script requires Python 2.0 or later.'
exec """
# Place entire original scriot here
"""

Note that this won't work if your original script contains triple quotes.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list