This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Amadiro
Recipients Amadiro
Date 2010-08-24.21:02:12
SpamBayes Score 4.8479336e-07
Marked as misclassified No
Message-id <1282683734.42.0.996381037193.issue9676@psf.upfronthosting.co.za>
In-reply-to
Content
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/
History
Date User Action Args
2010-08-24 21:02:14Amadirosetrecipients: + Amadiro
2010-08-24 21:02:14Amadirosetmessageid: <1282683734.42.0.996381037193.issue9676@psf.upfronthosting.co.za>
2010-08-24 21:02:12Amadirolinkissue9676 messages
2010-08-24 21:02:12Amadirocreate