[Tutor] Of fish and foul...(aka the Perl require command)

Max Noel maxnoel_fr at yahoo.fr
Mon Apr 18 21:34:23 CEST 2005


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