1.http://python-china.org/t/77 understanding of Method binding
2.[python] Dir () differs from __dict__,__slots__
3.Descriptor HowTo Guide
4. How do I understand Python's descriptor?
5. Concise Python Magic-1
6. Concise Python Magic-2
7. Explain the differences between __get__ and __getattr__ and __getattribute__ in Python
8. Custom Classes
What is the relationship between type 9.Python and object?
Why do the next few pieces of code work correctly and what happens at runtime???
classMyInt (int):def __init__(Self, v):Pass defSquare (self):returnSelf * SelfdefHello ():Print 'Hello'N= MyInt (2)PrintN.__dict__PrintMyInt.__dict__N.hello=Hellon.hello ()PrintN.__dict__
ImportTypesclassLog (object):def __init__(self, f): Self.f=Fdef __get__(SELF,OBJ,CLS):PrintSelf.f.__name__,'called' returntypes. Methodtype (SELF.F, obj, CLS)classC (object): @Logdeff (self):PassC=C () c.f ()
classC1 (object): a='ABC' def __getattribute__(Self, *args, * *Kwargs):Print("__getattribute__ () is called") returnObject.__getattribute__(Self, *args, * *Kwargs)def __getattr__(self, name):Print("__getattr__ is called") returnName +"From getattr" def __get__(self, instance, owner):Print("__get__ () is called", instance, owner)return Selfdeffoo (self, x):Print(x)classC2 (object): D=C1 ()if __name__=="__main__": C=C1 () C2=C2 ()Print "=====" Print(C.A)Print "------" Print(c.zzzz)Print "------"c2.dPrint "------" Print(C2.D.A)
"Python" Class (Data + doubts)