標籤:-- pass 運行時 資料 tor span nbsp org rip
1.http://python-china.org/t/77 有關method binding的理解
2.[Python] dir() 與 __dict__,__slots__ 的區別
3.Descriptor HowTo Guide
4.如何理解 Python 的 Descriptor?
5.簡明Python魔法 - 1
6.簡明Python魔法 - 2
7.詳解Python中 __get__和__getattr__和__getattribute__的區別
8.定製類
9.Python 的 type 和 object 之間是怎麼一種關係?
下面的幾段代碼為什麼能夠正確運行,運行時都發生了些什嗎???
class MyInt(int): def __init__(self, v): pass def square(self): return self * selfdef hello(): print ‘hello‘n = MyInt(2)print n.__dict__print MyInt.__dict__n.hello = hellon.hello()print n.__dict__
import typesclass Log(object): def __init__(self, f): self.f = f def __get__(self,obj,cls): print self.f.__name__, ‘called‘ return types.MethodType(self.f, obj, cls)class C(object): @Log def f(self): passc = C()c.f()
class C1(object): a = ‘abc‘ def __getattribute__(self, *args, **kwargs): print("__getattribute__() is called") return object.__getattribute__(self, *args, **kwargs) def __getattr__(self, name): print("__getattr__ is called") return name + "from getattr" def __get__(self, instance, owner): print("__get__() is called", instance, owner) return self def foo(self, x): print(x)class C2(object): d = C1()if __name__ == "__main__": c = C1() c2 = C2() print "=====" print(c.a) print "------" print(c.zzzz) print "------" c2.d print "------" print(c2.d.a)
【python】類(資料+疑惑)