python
This is an old revision of the document!
−Table of Contents
Python
Doc
- Doc python current (python.org)
- Doc python 2.6.4 (local)
- Télécharger Doc python 2.6.4 (local, tar.bz2)
- Télécharger Doc python 2.6.4 (local, zip)
- DiveIntoPython fr (developpez.com)
Basics
- Simple statements (official doc)
- Compound statements (official doc)
- HowTo Unicode (official doc)
- HowTo's (official doc)
Unicode
RegExp
PyGTK
Tkinter
Threading
Advanced Python
- Le décorateur (explication compréhensible, rare sur le web)
- Sorting (official doc)
Recipes
Advocacy
- Présentation de Luxor-XUL, qui comprends un plaidoyer pour Python assez synthetic
- Python Advocacy HowTo (from official doc)
ErrorMsg
- re:
Common Bad Programming Pattern
Référence à un objet
Lorsque l'on fait un assignement sur un objet, Python réalise une copie par référence (sorte de pointeur, hard link). Tout assignement sur le nouveau nom affecte naturellement le premier nom puisqu'ils référencent le même objet.
class A(): c = 1 a = A() b = a b.c = 2 # a.c returns 2 d = A.c e = d e = 2 # d.c returns 1
Cependant, lorsque l'on fait un assignement sur un attribut d'un object, le nom vient référencer la valeur retournée par l'attribut. L'assignement d'une nouvelle valeur ne modifira pas la valeur de l'attribut de l'objet. Cela se comprend facilement:
a = A() >>> a # returns <class __main__.A at 0x02433150> (la référence) b = a.c >>> b # returns 1 (la valeur)
Pour référencer l'attribut d'un objet, utiliser getattr (super puissant!)
f = getattr(a, "c")
Cool Stuff
python.1280248423.txt.gz · Last modified: 2010/07/27 18:33 by ginko