TechTalk: from python 2.x to python 3

by Álex 2013-02-12 00:30 talks python migration python3k

Introduction

This are some notes that I took while the talk that I saw today, the original title of the talk that I had the chance to see today was: “Switch to Python 3… Now… Inmediately” by the professor Russel Winder.

More or less all that you will find here is a transaction, just ordered in my style and perhaps with some notes by myself.

Python 2.x remains being the default python. Too many people and organizations are afraid of the change.

Python software foundation should declare python 3 the default python immediately.

Problems

Companies and people

Migration

Justifications

Python 2 is a dead end and python 3 is the developing future.

This piece of code is compatible with both versions, why don’t use them?

print(x)
exec(x)

Problem: print(x) support multiple parameter in python 3, so, let’s import the function from future to have the same behaviour in python 2.x:

from __future__ import print_function

Let’s make it bigger:

from __future__ import (
    division,
    absolute_import,
    print_function,
    unicode_literals
)

With this we will avoid problems with floats on divisions, add . to the imports, import the python3 version of print and work always with unicode.

Another problem is the list-comprehensions which will change a little bit, instead create list, they will create sets.

Some other problems

python 2 is strict, but python 3 is kinda lazy.

map(lambda x: x * x, filter(lambda x: x % 10 == 0, range(100))

Will produce an iterator in python 3, in python 2 is a data structure.

This is one of the biggest issues into the migration, other functions with same problems will be, for example: items, keys, values, iteritems, iterkeys & itervalues which in python 3 will become: items, keys & values.

If you want a data structure instead a iterator, you should make it manually:

range(10)  # python 2.x
tuple(range(10)  # python 3

Concurrency

At least IronPython and Jython do not have a GIL as CPython and PyPy do.

There is an experiment to mode GIL out of PyPy.

Actors : communicate processes with messages.

Dataflow : operators connected by channels with activity triggered by arrival of data on the channels.

CSP : we have PyCSP and PythonCSP.

Data parallelism

Transform a sequence to another sequence where all individual actions happen at the same time. Python has not a lot of utilities for that, since Go or D do.

Futures are the future

concurrent.futures : python 3.2 package to abstract over threads and processes to give an asynchronous function call and future system.

Under challengue

Funny points


Comments

comments powered by Disqus

polo is made with by @agonzalezro