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
  2. Why use 3: How to pitch Python 3 to Management

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) 

Inhalt abgleichen
Willkommen im Weltenwald!

Beliebte Inhalte

sn.1w6.org news

Draketo neu: Beiträge