User Tools

Site Tools


python_cheat_sheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
python_cheat_sheet [2010/06/18 18:31] ginkopython_cheat_sheet [2014/04/01 16:25] ginko
Line 9: Line 9:
     * Argv: (nécessite l'import du module ''sys'')<code python>argument_1=sys.argv[1]</code> (NB: argv[0] renvoie le nom du script)     * Argv: (nécessite l'import du module ''sys'')<code python>argument_1=sys.argv[1]</code> (NB: argv[0] renvoie le nom du script)
     * Il existe aussi une implémentation de getopt (//cf//. [[http://diveintopython.adrahon.org/scripts_and_streams/command_line_arguments.html|Dive into python - CLI]])     * Il existe aussi une implémentation de getopt (//cf//. [[http://diveintopython.adrahon.org/scripts_and_streams/command_line_arguments.html|Dive into python - CLI]])
 +===== Packaging ===== 
 +  * Encapsulation pour librairie autonome <code python>if __name__ == "__main__": 
 +    main()</code>
 ===== Variables ===== ===== Variables =====
   * Listes (mutable)<code python>a=[1, 'c']</code>   * Listes (mutable)<code python>a=[1, 'c']</code>
Line 35: Line 37:
 ===== IO ===== ===== IO =====
   * Ouvrir un fichier <code python>#'r'=read, 'w'=write, 'a'=append, 'r+'=read & write   * Ouvrir un fichier <code python>#'r'=read, 'w'=write, 'a'=append, 'r+'=read & write
-fichier=open('/path/to/file','r')</code>+fichier=open('/path/to/file','r') 
 +# il faut alors fermer le fichier 
 +# une métode qui referme le fichier proprement: 
 +with open('/tmp/workfile', 'r') as f: 
 +</code>
   * ''IOError'' (erreur d'entrée sortie)   * ''IOError'' (erreur d'entrée sortie)
   * Sortie vers le shell: <code python>print 'hello'</code>   * Sortie vers le shell: <code python>print 'hello'</code>
python_cheat_sheet.txt · Last modified: 2015/01/02 13:03 by ginko