New submission from Amadiro <jwrings...@gmail.com>:

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/

----------
components: Interpreter Core
messages: 114826
nosy: Amadiro
priority: normal
severity: normal
status: open
title: Keyword to disambiguate python version
type: feature request
versions: Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9676>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to