Requiring a certain version of interpreter?

Thomas Wouters thomas at xs4all.nl
Wed Jun 28 06:41:43 EDT 2000


On Wed, 28 Jun 2000 06:08:36 -0500, Chris Armstrong <punck at PenguinMints.cx>
wrote:
>In article <Lqj65.4362$h8.209230 at news-west.usenetserver.com>, Matthew
>Cline <matt at nightrealms.com> wrote:
>> Is there any builtin feature, or common module, that handles requiring
>> at least a certain version of the Python interpreter to be used for a
>> script?  Perl has 'require' for this purpose.

>>>> import sys 
>>>> print sys.version
>1.5.2 (#0, Apr  3 2000, 14:46:48)  [GCC 2.95.2 20000313 (Debian GNU/Linux)]

>There may a way to just get the version number only, but if nothing else this 
>will work.

Python 1.6 has sys.version_info, which is a tuple with version info:

>>> sys.version_info
(1, 6, 0, 'alpha', 2)

But no, there is no builtin way to 'require' a version. Most new features
break cleanly with old versions of Python (like keyword arguments) so the
usual remedy is to say 'Python 1.5 required!' near the top of the docs, and
point people there when they complain it doesn't work ;-)

And for the bug-prevention scheme, you can use 'if sys.version_info[1] < 6:'
in Python 1.6 (which will, of course, be bugfree.)

Thomas.



More information about the Python-list mailing list