Porting code from Python 2 to Python 3 is made easier by using 2to3. This application will find patterns that should be changed to keep the same behavior in Python 2 and 3.

However, 2to3 is sometime too conservative, trying to keep the exact same semantic.

For instance, dictionaries functions .items(), .keys() and .values() now (as in Python 3) return a view and not a list.

d = {'foo' : 'bar', 'bla': 'blo'}
keys = d.keys()
type(keys)
<type list>

While in Python 3

d = {'foo' : 'bar', 'bla': 'blo'}
keys = d.keys()
type(keys)
<class dict_keys>

If you run 2to3 on this snipet, you will get:

d = {'foo' : 'bar', 'bla': 'blo'}
keys = list(d.keys())
type(keys)
<type list>

This change guarantee that the semantic is exactly the same. However this change is often uneeded. In fact, the dict_keys class implement __iter__, __contains__ and __len__.

We can use the dict_keys in a for loop:

d = {1: 'one', 2: 'two', 3: 'three'}
for k in d.keys():
    print(k)
1
2
3

We can also check that a given key exists in the dictionary:

d = {1: 'one', 2: 'two', 3: 'three'}
if 2 in d.keys():
    print("Found")
found

While maintaining the same semantic, transforming the class into a list can waste many CPU cycles.


@FOSDEM

mer. 08 janvier 2014 by Rémi Duraffort

We will be at FOSDEM to talk about PRoot and some other tools based on it.

Cedric will do a Lightning talk saturday about syscall instrumentation. He will present some tools, based on syscall instrumentation, that we develop and use at STMicroelectronics:

  • PRoot, emulate chroot, bind mount and binfmt_misc for ...
read more

Pretending to be root inside PRoot

jeu. 21 novembre 2013 by Rémi Duraffort

While working on PRoot to improve the extension that fake the root user, I (re)discovered an old article that I never published before. So let's focus on the fake_id0 feature and on how it allows to use package manager directly inside the root file systems.

Some root causes ...

read more

PRoot now in Debian

mar. 20 août 2013 by Rémi Duraffort

A really short message to inform you that PRoot is now part of Debian Sid.

You can now install PRoot with apt-get install proot.

Enjoy !

read more

Scaling the time

lun. 24 septembre 2012 by Rémi Duraffort

Using valgrind on time-dependent softwares like VLC media player is often a nightmare and leads to poor results. Let's present a simple and elegant way to workaround this issue

Valgrind and realtime softwares

Valgrind is a really useful tool that checks for memory leaks, wrong memory access and many ...

read more

Making VLC at home

ven. 04 mai 2012 by Rémi Duraffort

In my previous article, I showed a way to setup and jump into a root file system in order to test a software in this environment.

Using PRoot, such task looks really easy and does not require any privileges. We will now finish this setup in order to build and ...

read more

PRoot sorcery

lun. 16 avril 2012 by Rémi Duraffort

A good practice for software developer is to provide a test suite while developing a software. When developing for Linux, it's also a good practice to compile the software and run the test suite on many distributions like Debian, Ubuntu, Fedora, ArchLinux, Centos, Slackware and for both i386 and ...

read more

Born to be PRoot

lun. 09 avril 2012 by Rémi Duraffort

It's been a long time since my last post on thit blog. To start again in a good shape I will seize the opportunity of a new version of PRoot to present this open source software in a cycle of articles.

What is PRoot about?

PRoot is a user-space ...

read more

VLC on Android

mer. 02 février 2011 by Rémi Duraffort

A lot of people are asking about the status of VLC media player on Android. We usually answered that we are working on it. Now that some good progresses has been done, lets look at the current status of VLC media player for Android.

Current status

After two months of ...

read more

Google Mentor Summit (part2)

jeu. 11 novembre 2010 by Rémi Duraffort

We went to the Google Mentor Summit in California for the week-end, let's talk a bit about it ...

The Google Mentor Summit

Every year, Google organizes the Google Summer of Code. This event is an opportunity for students to work on Open Source projects during the summer and being ...

read more