30 October 2012 Python: Copier des objets avec le module copy Les Bibliothèques Standards import copy a = [[1],[2],[3]] # Création d'une liste b = copy.copy(a) # Copier l'objet liste priimport copy a = [[1],[2],[3]] # Création d'une liste b = copy.copy(a) # Copier l'objet liste pri python
29 October 2012 Python: Exemple d’utilisation du module symbol Les Bibliothèques Standards import symbol print "print", symbol.print_stmt print "continue", symbol.continue_stmt print "returimport symbol print "print", symbol.print_stmt print "continue", symbol.continue_stmt print "retur python
28 October 2012 Python: Compilation et exécution dynamique d’un script Les Bibliothèques Standards code_script = """ print 'Apprendre à programmer' """ # Compiler le script try code = compile(ccode_script = """ print 'Apprendre à programmer' """ # Compiler le script try code = compile(c python
27 October 2012 Python: Exemple d’utilisation de la fonction apply Les Bibliothèques Standards def function(a, b): print a, b apply(function, ("France", "Paris")) apply(function,([8,5])) apdef function(a, b): print a, b apply(function, ("France", "Paris")) apply(function,([8,5])) ap python
26 October 2012 Python; Accéder au registre des Windows pour extraire l’utilisateur courant Les Bibliothèques Standards import _winreg explorer = _winreg.OpenKey( _winreg.HKEY_CURRENT_USER, "SoftwareMicrosoftimport _winreg explorer = _winreg.OpenKey( _winreg.HKEY_CURRENT_USER, "SoftwareMicrosoft python
25 October 2012 Python: Lire des lignes d’un module Les Bibliothèques Standards import linecache print linecache.getline("test.py", 5) print linecache.getline("exemple.py", 9)import linecache print linecache.getline("test.py", 5) print linecache.getline("exemple.py", 9) python
24 October 2012 Pyton: Obtenir la touche appuyée par l’utilisateur Les Bibliothèques Standards import msvcrt print "Pour quitter appuyer sur ESC" while 1: char = msvcrt.getch() if charimport msvcrt print "Pour quitter appuyer sur ESC" while 1: char = msvcrt.getch() if char python
23 October 2012 Python: Installer une fonction de profilage avec le module sys Les Bibliothèques Standards import sys def exemple(n): j = 0 for i in range(n): j = j + i return n def primport sys def exemple(n): j = 0 for i in range(n): j = j + i return n def pr python
22 October 2012 Python: Exemple de garbage collection Les Bibliothèques Standards import gc gc_was_enabled = gc.isenabled( ) if gc_was_enabled: gc.collect( ) gc.disable( )import gc gc_was_enabled = gc.isenabled( ) if gc_was_enabled: gc.collect( ) gc.disable( ) python
21 October 2012 Python: déboguer un programme Les Bibliothèques Standards import pdb def test(n): j = 0 for i in range(n): j = j + i return n db = pdb.import pdb def test(n): j = 0 for i in range(n): j = j + i return n db = pdb. python