Convertir un code python en C++ puis le compiler.
Voilà une super bonne nouvelle pour la communauté des utilisateurs de python, un espoir de compilation grâce au formidable travail de l’équipe de shedskin.
Grâce à ce petit programme vous pourrez convertir vos codes python en C++ puis les compiler et augmenter les performances de 20 à plus de 200*
Limitations :
Supporte les versions python de 2.4 à 2.6
Ne supporte pas le typage dynamique (Un variable int doit rester int par exemple)
Il supporte ces librairies seulement mais il est possible de compiler une librairie ou ses propres librairies, moyennant adaptation du code.
- bisect
- collections
- ConfigParser
- copy
- datetime
- fnmatch
- getopt
- glob
- math
- os (il manque certaines fonctions sous Windows)
- os.path
- random
- re
- socket
- string
- sys
- time
Plus précis, voir en bas de ce tutoriel un extrait de la documentation officielle (en)
Tout d’abord télécharger la dernière release de shedskin :
http://sourceforge.net/projects/shedskin/files/
Exécuter le programme d’auto extraction choisissez le dossier où extraire shedskin.

Allez dans le répertoire d’extraction ouvrez le bat nommé init.bat.
Une fenêtre dos s’ouvre.

Placez votre fichier python .py dans le dossier d’en dessous nommé shedskin.
Pour convertir py -> C++ tapez dans la commande : shedskin monpy.py (exemple).
Shedskin doit bien être marqué dans la console !
La conversion débute et vous indique si votre code ne comporte pas d’erreurs.

Un fichier monpy.cpp, un monpy.hpp et un pythot.ss.py viennent d’êtres créés, ils serviront à la compilation.
Compiler son code :
Maintenant tapez juste après avoir converti votre code : make run , Tout simplement.
La compilation est en cours puis le programme se lance.
Tapez seulement make pour seulement compiler.

Voilà c’est compilé, votre exe se trouve dans le répertoire shedskin : shedskin-0.2\shedskin.
Il nécessite libpcre-0.dll et gc.dll.
Shed Skin translates pure, but implicitly statically typed, Python programs into C++. The static typing restriction means that variables can only ever have a single, static type. So, for example,
is not allowed. However, as in C++, types can be abstract, so that, for example,
where A and B have a common base class, is allowed.
The typing restriction also means that the elements of some collection (list, set, etc.) cannot have different types (because their subtype must also be static). Thus:
are allowed, but
are not allowed. Of course, dictionary keys and values may be of different types:
In the current version of Shed Skin, mixed types are also permitted in tuples of length two:
a = (1, [1]) # good
In the future, mixed tuples up to a certain length will be allowed.
None may only be mixed with non-scalar types (i.e., not with int or float):
Integers and floats can often be mixed, but it is better to avoid this where possible, as it may confuse Shed Skin:
Shed Skin will only ever support a subset of all Python features. The following common features are currently not supported:
- reflection (getattr, hasattr), eval, or other really dynamic stuff
- arbitrary-size arithmetic (integers become 32-bit on most architectures!)
- generator expressions
- variable numbers of arguments and keyword arguments
- multiple inheritance
- nested functions and classes
- inheritance from builtins (excluding Exception and object)
- some builtins, such as map, filter and reduce
- overloading __iter__ and __call__
Some other features are currently only partially supported:
- class attributes must always be accessed using a class identifier:
- self.class_attr # bad
- SomeClass.class_attr # good
- anonymous function passing works reasonably well, but not for methods, and they cannot be contained:
- var = lambda x, y: x+y # good
- var = some_func # good
- var = self.some_method # bad
- [var] # bad