Python

Linked items to a Tree

Let’s say you receive a list of 2 linked items having a “is included in” relation. For example, you receive this list :

Here (‘cpqswcc’, ‘compaq’) means ‘cpqswcc’ is included in ‘compaq’. You may want to build a relation tree like this :

The cool function to do that would be the one in this code :

   

Python

How to get Class attributes order

Before python 3.6 it was difficult to get attributes order from a class. Let’s say, for instance, you want to create a listing class which contains columns to display :

With python 2.7 you will get :

With python 3.5 you will get :

And finally, with python 3.6, there is no problem any more : attributes…

Continue Reading

Python

How to dynamically create a class with some mixins

Let’s say you want to create a class that includes mixins having names that are known at execution time only, you would do some thing like this :

To get mixins_classes, juste use importlib to get mixins classes from names. A function that would create an instance of such a dynamic class would be something like this :

Continue Reading

Python

Hello world!

… my first post