[Tutor] Checking for Python version
Wayne
srilyk at gmail.com
Tue Oct 6 17:02:21 CEST 2009
On Tue, Oct 6, 2009 at 9:57 AM, Steve Willoughby <steve at alchemy.com> wrote:
> On Tue, Oct 06, 2009 at 09:47:43AM -0500, Wayne wrote:
> > On Tue, Oct 6, 2009 at 9:46 AM, Steve Willoughby <steve at alchemy.com>
> wrote:
> >
> > > On Tue, Oct 06, 2009 at 09:42:04AM -0500, Wayne wrote:
> > > > On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts <
> cwitts at compuscan.co.za
> > > >wrote:
> > > > if sys.version < '2.4':
> > > > sys.exit("Need at least Python 2.4")
> > > >
> > > > AFAIK the string comparison is reliable
> > >
> > > Not quite. What happens when you compare '2.4' and '2.10'?
> > >
> >
> > >>> '2.4' > '2.10'
> > True
>
> Exactly. So it doesn't work.
>
> In typical software release numbering, 2.10 is the tenth
> minor version of the 2.x major version series, so 2.10 is
> later than 2.4, but comparing as ASCII strings, it comes
> out the other way around.
>
> Also note that '10.1' < '5.7'
>
Ah... I see now. A tuple comparison would work against the version though,
correct?
>>> import sys
>>> sys.version_info
(2, 6, 2, 'final', 0)
>>> sys.version_info > (2, 4, 0)
True
>>> sys.version_info > (2, 10, 0)
False
>>> sys.version_info > (1, 10, 0)
True
Which looks a lot cleaner (at least to me) than the OP... and has the
advantage of working for all versions ;)
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091006/715cba84/attachment.htm>
More information about the Tutor
mailing list