Zwillingssterns Weltenwald
Published on Zwillingssterns Weltenwald (http://www.xn--drachentrnen-ocb.de)

Startseite > Why Python 3?

Why Python 3?

At the Institute we use both Python 2 and Python 3. While researching the current differences (Python 3.5, compared to Python 2.7), I found two beautiful articles by Brett Cannon, the current manager of Python, and summarized them for my work group.

The articles:

  1. Why Python 3: Why Python3 exists [1]
  2. Why use 3: How to pitch Python 3 to Management [2]

The relevant points for us1 are the following:

  1. Why Python 3 was necessary:

    • Python2: string = byte-array.
      • Py3 avoids Encoding-Bugs in Unicode: all Strings are Unicode.
    • Python2: sources in ASCII. β in a comment needed # encoding: utf-8
      • Py3 uses utf-8 in source files by default.
    • Last chance: the cost of the chance increased every year.
  2. Why use 3 (relevant for us, e.G. for new projects):

    • int/long -> int
    • Unicode in Code: σ = sqrt(var) # only letters, but i.e. not Σ
    • H.dot(β) -> H @ β
    • chained exceptions: Traceback ... during handling ... Traceback — simplifies debugging
    • print() facilitates structured output2

The effect of these points is much larger than this short text suggests: avoid surprises, avoid awkward workarounds, and easier debugging.


  1. I have summarized them because I can not expect scientists (or other people who only use Python) to read the full articles, just to decide what they do when they get the channce to tackle a new project. ↩

  2. Example for print():
    nums = [1, 2, 3]
    with open("data.csv", "a") as f:
        print(*nums, sep=";", file=f) ↩

Werke von Arne Babenhauserheide. Lizensiert, wo nichts anderes steht, unter der GPLv3 or later und weiteren freien Lizenzen.

Diese Seite nutzt Cookies. Und Bilder. Manchmal auch Text. Eins davon muss ich wohl erwähnen — sagen die meisten anderen, und ich habe grade keine Zeit, Rechtstexte dazu zu lesen…


Source URL: http://www.xn--drachentrnen-ocb.de/english/free-software/why-python-3

Links:
[1] http://snarky.ca/why-python-3-exists
[2] http://snarky.ca/how-to-pitch-python-3-to-management