[Python-ideas] Keyword to disambiguate python version

Nick Coghlan ncoghlan at gmail.com
Thu Aug 26 23:52:25 CEST 2010


On Fri, Aug 27, 2010 at 5:25 AM, Jonny <jwringstad at gmail.com> wrote:
> I would propose that an idiomatic way is created, for instance a
> pragma or statement, which allows one to disambiguate the used python
> version in a manner that is both obvious for the human reader, and as
> well allows python to reject the script, should the wrong version of
> the interpreter be present. I think this is a quite common
> problem[1][2], which could be solved in a fairly easy and pragmatic
> way.

Your proposed solution doesn't help with either of the linked Stack
Overflow questions. The second one is completely covered by the
existing sys.version_info() function, as it is only asking how to
obtain the details of the running Python version. The first one is
subtler, asking how to deal with code that won't even compile on
earlier versions, so it will still fail to compile instead of
degrading gracefully on older versions, even if the file is flagged
somehow as requiring a later version.

So it isn't at all clear what is to be gained here over the
try-it-and-see-what-happens try/except approach (often best) or the
explicit "sys.version_info() >= required_version" check.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list