fork download
  1. class A():
  2. def __init__(self):
  3. self.a='a'
  4.  
  5. def foo_a(self):
  6. print('a')
  7.  
  8. class B():
  9. def __init__(self):
  10. self.b='b'
  11.  
  12. def foo_b(self):
  13. print('b')
  14.  
  15. a = A()
  16. print(dir(a))
  17. a.__dict__.update(B().__dict__)
  18. print(dir(a))
  19. print(a.a, a.b)
  20. a.foo_a() #works
  21. a.foo_b() #doesn't work
  22.  
Runtime error #stdin #stdout #stderr 0.03s 9984KB
stdin
Standard input is empty
stdout
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'foo_a']
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b', 'foo_a']
a b
a
stderr
Traceback (most recent call last):
  File "./prog.py", line 21, in <module>
AttributeError: 'A' object has no attribute 'foo_b'