classification
Title: Keyword to disambiguate python version
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Amadiro, benjamin.peterson
Priority: normal Keywords:

Created on 2010-08-24 21:02 by Amadiro, last changed 2010-08-24 21:07 by eric.araujo. This issue is now closed.

Messages (2)
msg114826 - (view) Author: Amadiro (Amadiro) Date: 2010-08-24 21:02
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.

Being a python beginner, I'm not well-adversed in the ways of idiomatic python, so feel free to reject or improve on my syntactic examples, these are merely meant to demonstrate my point.

Building on [3], I would suggest some syntax like this:

 #!/usr/local/bin/python
          # version: python-3
          import os, sys
          ...

Alternatively, some syntax could be used that allows one to use basic comparison operators, a range or even simple chained logical statements.

 #!/usr/local/bin/python
          # version: [2.4 .. 3.0] and not 2.6.1

          # or multiple clauses

          # version: >= 2.4.2
          # version: < 3.0
          # version: not 2.6.1
          # jpython-version: ...
          
          # or multiple keys

          # min-version: 2.4.2
          # min-jpython-version: 2.4.4
          # max-version: 2.6.1
          import os, sys
          ...

This way it should be fairly obvious to the casual reader which python version the program is intended to run under, and the python interpreter can simply reject to parse/execute the program, should it encounter an incompatible requirement.

References
[1] http://stackoverflow.com/questions/446052/python-best-way-to-check-for-python-version-in-program-that-uses-new-language-fe
[2] http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script
[3] http://www.python.org/dev/peps/pep-0263/
msg114829 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-08-24 21:04
Please post to python-ideas first, and note that no syntax changes are allowed until 3.3.
History
Date User Action Args
2010-08-24 21:07:10eric.araujosetstatus: open -> closed
stage: resolved
2010-08-24 21:04:50benjamin.petersonsetresolution: rejected

messages: + msg114829
nosy: + benjamin.peterson
2010-08-24 21:02:12Amadirocreate