[Python-3000] Namespaces are one honking great idea -- let's do more of those!

nathan binkert nate at binkert.org
Wed Feb 6 18:40:25 CET 2008


This is very similar to the #! idea and is really just an extension.

Python 2 clearly cannot execute python 3 code, but how hard would it
be to require something like a
__pyversion__ = 3 statement at the top of the file.  If the line does
not exist, the python3 binary would dlopen libpython2.x and execute
the code.  I understand that the syntax of the two versions are not
compatible, but couldn't the tokenizers be compatible?  Imagine the
python3 binary tokenizing the code, searching for the __pyversion__
line and if it does not exist, doing the dlopen and passing the
tokenized code to the python2.x binary (with some potential
translation to fix any token incompatibility).  if the libpython2.x.so
doesn't exist, then a VersionError could be raised.  If the initial
file does have a __pyversion__ and subsequent files do, then a
VersionError exception could be raised.  This solution could help deal
with code that requires new features.  For example, say I want to use
a with clause, I could require 2.6 or 3.0.

Sorry to prolong an already long conversation.

  Nate


More information about the Python-3000 mailing list