Thursday, December 9, 2010

inheriting from instance

>>> class A(object):
...    def __init__(*args): print args
...
>>> class B(A()): pass
...
(<__main__.A object at 0x2071fd0>,)
(<__main__.A object at 0x2077110>, 'B', (<__main__.A object at 0x2071fd0>,), {'__module__': '__main__'})
>>> B
<__main__.A object at 0x2077110>
>>> B()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'A' object is not callable
>>> dir(B)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
>>> B.__dict__
{}

No comments:

Post a Comment