[Tutor] Of fish and foul...(aka the Perl require command)
Smith, Jeff
jsmith at medplus.com
Tue Apr 19 18:21:35 CEST 2005
Thanks,
That does the trick. Rather than make a function, I'm likely to just
do:
if sys.version_info[:3] < (X,Y,Z):
raise RuntimeError
Jeff
-----Original Message-----
From: Max Noel [mailto:maxnoel_fr at yahoo.fr]
Sent: Monday, April 18, 2005 3:34 PM
To: Smith, Jeff
Cc: tutor at python.org
Subject: Re: [Tutor] Of fish and foul...(aka the Perl require command)
On Apr 18, 2005, at 19:59, Smith, Jeff wrote:
> Is there a Python equivalent to the Perl
>
> require 5.6.0
>
> Which enforces a minimum interpreter version?
As far as I know, no. But:
>>> import sys
>>> sys.version_info
(2, 3, 0, 'final', 0)
>>> (2, 4, 0) > sys.version_info
True
>>> (2, 2, 0) > sys.version_info
False
So you can create one yourself quite easily.
import sys
def require(version):
if sys.version_info < version:
raise OSError, "This program requires Python v%s or later" %
'.'.join(map(str, version))
>>> require((2,4,1))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in require
OSError: This program requires Python v2.4.1 or later
I'm not really sure what exception I should raise, though --
OSError
is the most appropriate, but not exactly the Right Thing... Oh, well.
*shrugs*
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
More information about the Tutor
mailing list