Leif Walsh wrote: > On Feb 2, 2008 8:38 PM, Ron Adam <[EMAIL PROTECTED]> wrote: > >> Instead of a shebang which depends on the shell, maybe a version >> specifier >> of some sort could be used? >> >> # -*- pyversions: 2.5, 2.6 -*- >> >> So if a python 3.x detects a too low a version, maybe it can try to >> restart >> the program with the highest installed version specified. (Or some >> variation of this.) >> > > There is already an idiom with other packages (pygtk etc.) that > suggests syntax like > > try: > python.require('3.1') > except: > print('Some warning about version incompatibility') > exit(1) > > This concern seems better addressed within the language itself, rather > than in the shebang (which would make the decision depend on the shell > and the packaging involved). > > Great idea. Since we've already got everything we need in version_info, this would be trivial and could address most of the issues raised ... something like this?
>>> def checkversion(maj, min, rel): ... version = sys.version_info ... if version[0] < maj or version[1] < min or version[2] < rel: ... raise Exception('Version %d.%d.%d of Python is required for this program' % (maj, min, rel)) ... >>> checkversion(2, 5, 0) >>> checkversion(3, 0, 0) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 4, in checkversion Exception: Version 3.0.0 of Python is required for this program >>> Cheers, T _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com