[Python-bugs-list] [ python-Feature Requests-491331 ] request sys.required_version
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 10 Dec 2001 14:25:43 -0800
Feature Requests item #491331, was opened at 2001-12-10 14:12
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=491331&group_id=5470
Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: Daniel Ortmann (dortmann)
Assigned to: Nobody/Anonymous (nobody)
Summary: request sys.required_version
Initial Comment:
In Perl, "require 5.04" conveniently specifies the
minimum level of Perl required to run the script.
I expected to find something similar in the Python sys
module, but this is as close as I can come:
import sys
assert (2,2) <= sys.version_info[:2], "python version
is too old!"
It seems to me that I should be able to say something like:
import sys
sys.required_version(2,2,0)
Thank you!
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-12-10 14:25
Message:
Logged In: YES
user_id=31435
Because Python has a full-blown exception system, it's
generally better to test for the feature you need than to
compare mysterious little integers. For example, suppose
you need list comprehensions. You have no idea which
version of Python first introduced them, and once you think
you've got it figured out, readers of your code are going
to have no idea that you *meant* "list comprehensions" when
you compare sys.version_info against (2, 0). So clearer
all around is:
try:
. eval("[i for i in range(2)]")
except SyntaxError:
. raise ImportError, "I require list comprehensions"
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=491331&group_id=5470