Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In [10]: class A(object): pass
- ....:
- In [11]: def f(self, x): print 'f called:', self, x
- ....:
- In [12]: A.f = f
- In [13]: a = A()
- In [14]: a.f(2)
- f called: <__main__.A object at 0x1b6a910> 2
- In [15]: a.f.__f
- a.f.__format__ a.f.__func__
- In [15]: a.f.__func__.__name__
- Out[15]: 'f'
- In [16]: a.__class__
- Out[16]: <class '__main__.A'>
- In [17]: a.__class__.__name__
- Out[17]: 'A'
- In [18]: dir(a)
- Out[18]:
- ['__class__',
- '__delattr__',
- '__dict__',
- '__doc__',
- '__format__',
- '__getattribute__',
- '__hash__',
- '__init__',
- '__module__',
- '__new__',
- '__reduce__',
- '__reduce_ex__',
- '__repr__',
- '__setattr__',
- '__sizeof__',
- '__str__',
- '__subclasshook__',
- '__weakref__',
- 'f']
- In [19]: del A.f
- In [20]: a.f()
- ---------------------------------------------------------------------------
- AttributeError Traceback (most recent call last)
- /home/me/<ipython console> in <module>()
- AttributeError: 'A' object has no attribute 'f'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement