Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class A(object):
  2. pass
  3.  
  4. class B(object):
  5. __slots__ = ('foobar',)
  6.  
  7. def __init__(self):
  8. self.x = 123
  9.  
  10. class C(A):
  11. __slots__ = ('foobar',)
  12.  
  13. def __init__(self):
  14. self.x = 123
  15.  
  16. >>> A()
  17. <__main__.A object at 0x10caf4d10>
  18. >>> C()
  19. <__main__.C object at 0x10caf38c0>
  20. >>> B()
  21. Traceback (most recent call last):
  22. File "slots.py", line 18, in <module>
  23. B()
  24. File "slots.py", line 8, in __init__
  25. self.x = 123
  26. AttributeError: 'B' object has no attribute 'x'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement