5 ms·
Why don't we have a single interpreter that can run both Python 2 and 3 code?
by GNU_James 6y ago
Why don't we have a single interpreter that can run both Python 2 and 3 code?
- yedpodtrzitko 6y agoHow would that work? I assume you'd still need to declare which version you want to run as, and if any library you want to import wouldnt be compatible, then either you are where you are right now, or it would bring a lot of backward/forward incompatibility issues with unicode/bytes/strings/syntax etc.
- nhumrich 6y agoHow would it know which version a file was supposed to use?
- CamperBob2 6y agoSame way a shell script specifies what interpreter to run, maybe? Meaning some form of standardized comment header.
- EamonnMR 6y agoIn that case you wouldn't need a compatible interpreter, you'd just specify the interpreter you want in the shebang. Python does not usually use shebangs because you're supposed to run in a virtualenv, not shebang your files to your system python.
- ben509 6y agoBecause nobody wants it. You probably could run GraalPython, which is Python 3 and Jython, which is 2.7, since they both run inside a JVM.[1] There'd be no interop between the languages, though. To get that in Graal, you'd have to reimplement python 2 using Truffle. That's a massive effort compared to simply running 2to3 to migrate your old code to Python 3. [1]: https://www.graalvm.org/reference-manual/python/Jython/ https://www.graalvm.org/reference-manual/python/Jython/
- tclancy 6y agoWhy don’t we have a single interpreter that can run every language? And how come I can’t get no Tang round here?
- kortex 6y agoYou can, it's called use __future__, six, and 2/3 compatible idioms. I've been writing code (begrudgingly) like this for years. Test suite runs on 2.7-3.6 no problem, albeit annoying to write vs pure py3.