3 ms·
One thing that I don't really understand is why not adopt a new syntax to allow users to specify the version of Python a file should be imported and run under.
by kylec 17y ago
One thing that I don't really understand is why not adopt a new syntax to allow users to specify the version of Python a file should be imported and run under. Just have the interpreter pick 2.X by default, but if there's something like
##python-3.0
as the first line, then load the file with the 3.0 interpreter. This way you can intermix 2.X libraries with an otherwise 3.X project without having to deal with the whole 2to3 thing.
- pcc 17y agoIn a *nix environment, set the shebang line of the file to point to the precise interpreter you want to use. Any imports that file makes will be from the /usr/lib/pythonX.Y for that version of the interpreter. (In order to get the library installed into that path in the first place, it must have been done via that version of the interpreter specifically, so its quite possible to keep 3.x and 2.x versions of the same library quite isolated). Of course imports can also come from the local dir, via pythonpath and the various manipulations thereof (buildout, virtualenvs etc), so there are a few degrees of freedom via which to manage things. May be worth pointing out that a file and all its imports will only be running under one interpreter, so a file running on 3.x (via shebang line, say), will not be able to use a 2.x library (even if placed in the correct path) where the code of that library is fundamentally not 3.x compatible.