Home python Why use Python2 instead Python3?

Why use Python2 instead Python3?

Author

Date

Category

Why do some people continue to use the previous version of the interpreter, why he had not yet died and been forgotten?

The third version has gone far ahead (one async and a new GIL are worth), many libraries have been ported (previously, for example, was an occasion to use Py2 – OpenCV, but it was ported)

.

The only occasion – support for older projects and the inability to move, but still there are those who start new projects Py2. New issues appear on StackOverflow.

Why, what obvious reasons?


Answer 1, Authority 100%

The obvious reason is the incompatibility of the majority of older workers tested Python 2 to Python 3 programs.

Even if most of the changes is trivial (and can be automated), the transition to Python 3 requires the test of time, and programmers who need to justify spending. Python 2 itself is already good language. Python 3 places better, but for some tasks may be even worse than at first sight.

Even if developers can find the time to go to a new language, taking into account that people are curious programmers, Python 3 can compete with the transition to other languages ​​such as Go, OCaml (Python 3 is not compatible, but it “is not compatible enough” if something I want to try something new.)

The original Python adaptation 3 did not help, the fact that the first version (to Python 3.2-3.3) were not intended for wide use. Most of the network books / resources used Python 2 syntax. Usually, the pre-command python launches Python 2 on POSIX systems.

Most of the living popular libraries work like Python 2 and 3. There is a “long tail” of libraries that only Python 2 work (public and internal tools).

Because of the stated long-term (currently until 2020) official support for Python 2, people are a little lost on the remaining Python 2 (although people often underestimate the time programs of life).

To force programmers to learn the difference between the text shown in the
a Unicode strings bytes and creates a noticeable barrier for changing versions
for new code. Especially, if the programmer is working in an environment where
Or text generally represented as a byte encoded in utf-8
worse, semantic text interfaces used historically
byte API to POSIX systems that allow for arbitrary
a sequence of bytes (file names, command line parameters,
environment variables) that requires such things as surrogateescape,
to continue to work with Unicode by default.

lessons

In order not to repeat the mistakes could have been avoided changing the basic version and
enter new changes in stages (Python 4 Python 3 should not be understood):

  • does not accumulate a lot of incompatible changes that need to be
    learn how to use and look for a way to make friends with the old code
    (Low transition costs)
  • maybe most of the new features clean under from __future__ import
    division, print_function, unicode_literals, etc
    , which is included
    after a few issues by default (you can test,
    convert code one module at a time)
  • to publish PyPI modules to facilitate the transition from version to version,
    for example, contextlib2 , pathlib2 , subprocess32 , etc
  • provide the ability to run old code to the new version free
    changes (to support older programs is relatively
    only if the other items are also implemented)
  • to convert the new version of the old to the new code in the old
    Executable environment (new programs could be on the new version
    language to write and perform in the old environment) (3to2 instead
    2to3-see. futurize and pasturize
    scripts
    )
  • limited support for older versions (as it is now 3.2, 3.3, 3.4, 3.5
    supported) – only one official language of the current version
    (To create an unnecessary choice is not)
  • use semver for the language can be harmful for the psychological
    reason: instead of 3.0 it was possible to release 2.6 with a smaller set
    new features (changing the main figure can scare without reason)
  • slowly remove old especially malicious features – mention in
    documentation is the best way, but actually delay for several years
    Removing the old code (adaptation for each new version in any
    case may require work – so the barrier between the transition to each
    version is not too high)

As a result:

  • people who love new shiny things can use them,
    Not waiting for the transition of the entire code base to the new version
  • people who need to continue to work, also satisfied with old
    The code should not break (with the exception of the usual expected
    Turning nuts when moving to a new version)
  • especially conservative people continue to sit on Python 2.4, 2.6
  • newcomers just start with the current only version

Answer 2, Authority 70%

For me, one of the obvious reasons are all sorts of UNIX / Linux distributions, where the default is Python2 and the lion’s share of simple users does not have rights to put Python 3 at the system level. Consequently, all their developments will not be correct (if it is not specifically acquired) to work for other users on Python 2.

That’s when all popular distributions will go out with Python 3 by default, then you can gradually begin to forget about Python 2, IMO …


Answer 3, Authority 50%

python2 and python3 are now equally popular, Python2 continues to write libraries, improve. What is the Python2 syntax better than Python3, more convenient.
For example, print in my opinion it is more convenient to write without brackets. For Python2 there are modules that did not do for Python3. Moreover, Python 2.7 I stood from the very beginning, many do not want to fall from Python2 syntax – so there are many

In general, two in parallel developing versions of Python language – 2 and 3 are in demand.


Answer 4, Authority 10%

a non-obvious problem, which he himself somehow died: Even if the library declared support for Python 3, it is still unknown by what quality it is. For example, a year or two ago I made an attempt to go to PY3: I needed Pyserial, so he was buggy on elementary things, despite the fact that it worked with PY2 without problems, I had to return to PY2.

Also in the comment of annual prescription on Hacker News, it was said that there is a similar problem with Machine Learning Libraries: there is support PY3, but they are amazing and therefore the people still use PY2.

In Comment (March 2016) To the article Maentener Libraries say that the bugs manifest themselves on the Py3 months hang, because everything is on PY2. Original:
“A trove classifier says nothing about the quality of running a polyglot library on Python 2 or Python 3. I say this as someone who maintains polyglot libraries where I’ve had Python 3 bugs persist for months, because everyone actually uses Python 2.”
https://blogs.msdn.microsoft .com / pythonengineering / 2016/03/08 / Python-3-Is-winning /

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions