Advertisement
Guest User

Untitled

a guest
Sep 27th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. class Meta(type):
  2. def __getattribute__(self, name):
  3. d = type.__getattribute__(self, "__dict__")
  4. if name not in d:
  5. raise AttributeError
  6. else:
  7. return d[name]
  8.  
  9. class A(metaclass=Meta):
  10. x = 1
  11.  
  12. class B(A):
  13. y = 2
  14.  
  15. print(B.y) #2
  16. print(B().y) #2
  17. print(B().x) #1
  18. print(B.x) #AttributeError
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement