3 ms·
Because you actually can write code that is compatible with both Python 2 and 3. Also major issues people have with migration is unicode. In respect of unicode
by takeda 11y ago
Because you actually can write code that is compatible with both Python 2 and 3.
Also major issues people have with migration is unicode. In respect of unicode, majority of the code is simply broken and fails to work on Python 3 because Python 3 is more strict about it.
In Python 2 you store text and binary data as bytes (no distinction, there is unicode type but it's more hassle to use it and frankly almost no one does use it) while in Python 3 text and binary data are two distinct types.
So if you have code in Python 2 and you did not distinguish what is text and what is binary now you have to go through your entire code and identify all those parts, this is especially hard since Python is dynamically typed language and you don't have type checker to help you with that.
This is also why it is much easier to write Python 3 code and make it run on Python 2 as well than the other way around.
As for having interpreter compatibility layer. First python does not care about extension you use, and unlike some languages it actually allows you to install multiple versions at the same time without conflicts (checked 2.4 all the way to 3.5). You can easily control which version you want to use by shabang, for example:
#! /usr/bin/env python2
#! /usr/bin/env python3
#! /usr/bin/env python3.5
- colanderman 11y agoYou can also write code that is compatible with both C and Perl. Doesn't make it a good idea. Shebang doesn't work on a per-module basis, which is what I am advocating. If there were a way to specify versions at that granularity, there would be no need for 2/3 polyglot tricks.
- takeda 11y agoThat's a strawman argument. Majority of python libraries are written that way. I guess I'm incredibly lucky or you're incredibly unlucky, because I did not run into a library that would only run on Python 2. Ok, I did run into some, but those were no longer maintained and frankly I would not use them even on Python 2.
- berntb 11y agoSo the problems with upgrading from Python 2 to 3 because of library support are over? Including linked C code? Or is that just your lucky experience?
- semi-extrinsic 11y agoThe problem with shebangs used to be (don't know if it still is) that quite a few OS's had python 2.X, but no actual binary called `python2`, just `python`.
- takeda 11y agoPython installs itself as pythonX.Y (for example python2.7) then symlinks such as python2 (pointing to python2.7) and python (pointing to python2) are made.
- semi-extrinsic 11y agoIt's mentioned in PEP0394 that some older distros did not have python2 even though python 2.X was installed. Since RedHat still supports a release with Python 2.4 as the default, I guess it might still crop up on some boxen, at least for another year until RHEL 5 reaches end-of-life. Assuming python points to python2 will also break stuff, though, there are more bleeding-edge OS's where python points to python3 and has done so for years (e.g. ArchLinux).