>>> # _______________________________________________________________ >>> # bound methods are implemented using .__get__ >>> def f(self, x): ... return self + x ... >>> method = f.__get__(1, int) >>> method >>> method(14) 15 >>> l = [] >>> app = l.append >>> app(12) >>> app >>> app(12) >>> app(12) >>> app(12) >>> l [12, 12, 12, 12] >>> >>> # _______________________________________________________________ >>> # implementing static methods using __get__ >>> class Staticmethod(object): ... def __init__(self, f): ... self.f = f ... def __get__(self, *args): ... return self.f ... >>> def static(): ... return 41 ... >>> class X(object): ... f = Staticmethod(static) ... >>> x = X() >>> x.f >>> x.f() 41 >>> class X(object): ... def f(): ... print 42 ... return 45 ... f = Staticmethod(f) ... >>> x = X() >>> x.f() 42 45 >>> X.f >>> X.f() 42 45 >>> X.__dict__['f'] <__main__.Staticmethod object at 0x834f8ec> >>> X.f() 42 45 >>> # _______________________________________________________________ >>> # implementing a property using __get__ >>> class ReadProperty(object): ... def __init__(self, f): ... self.f = f ... def __get__(self, inst, cls): ... return self.f(inst) ... >>> class Y(object): ... def f(self): ... return self.x * 14 ... f = ReadProperty(f) ... >>> y = Y() >>> y.x = 2 >>> y.f 28 >>> y.x = 7 >>> y.f 98 >>>