9 September 2012 Python: Appel d’une fonction par son nom Les Bibliothèques Standards def getfunctionbyname(module_name, function_name): module = _ _import_ _(module_name) returdef getfunctionbyname(module_name, function_name): module = _ _import_ _(module_name) retur python
8 September 2012 Python: Analyser le chemin du script Les Bibliothèques Standards import sys # Importer le module 'sys' print "Le chemin a", len(sys.path), "membres" # Ajouter unimport sys # Importer le module 'sys' print "Le chemin a", len(sys.path), "membres" # Ajouter un python
7 September 2012 Python: Vérification des types avec le module operator Les Bibliothèques Standards import operator import UserList def dump(data): print type(data), "=>", if operator.isCallaimport operator import UserList def dump(data): print type(data), "=>", if operator.isCalla python
6 September 2012 Python: Exemple d’utilisation de module cmath Les Bibliothèques Standards import cmath print "pi", "=>", cmath.pi print "sqrt(-1)", "=>", cmath.sqrt(-1) """ pi => 3.141592import cmath print "pi", "=>", cmath.pi print "sqrt(-1)", "=>", cmath.sqrt(-1) """ pi => 3.141592 python
5 September 2012 Python: Accéder à une base de données spécifique avec le module shelve Les Bibliothèques Standards import shelve import gdbm def gdbm_shelve(filename, flag="c"): return shelve.Shelf(gdbm.open(fimport shelve import gdbm def gdbm_shelve(filename, flag="c"): return shelve.Shelf(gdbm.open(f python
4 September 2012 Python: Exemple d’utilisation du module posix Les Bibliothèques Standards import posix for file in posix.listdir("."): print file, posix.stat(file)[6]import posix for file in posix.listdir("."): print file, posix.stat(file)[6] python
3 September 2012 Python: Exemple de profilage d’un programme Les Bibliothèques Standards import profile def func1(x): for i in range(x): pass def func2(): for i in range(import profile def func1(x): for i in range(x): pass def func2(): for i in range( python
27 August 2012 Python: Installer un traceur avec le module sys Les Bibliothèques Standards import sys # définition d'un fonction def exemple(n): j = 0 for i in range(n): j =import sys # définition d'un fonction def exemple(n): j = 0 for i in range(n): j = python
27 August 2012 Python: Afficher le nom et les informations de la plateforme Les Bibliothèques Standards import sys print sys.platform,"=> ", if sys.platform == "win32": import ntpath pathmoduleimport sys print sys.platform,"=> ", if sys.platform == "win32": import ntpath pathmodule python