SHARE
TWEET

Untitled

a guest Jun 15th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >>> class Foo:
  2. ...     def bar(self):
  3. ...         return 'bar on Foo'
  4. ...
  5. >>> class Spam(Foo):
  6. ...     def bar(self):
  7. ...         return 'bar on Spam'
  8. ...
  9. >>> spam = Spam()
  10. >>> super(Spam, spam)
  11. <super: <class 'Spam'>, <Spam object>>
  12. >>> super(Spam, spam).__thisclass__
  13. <class '__main__.Spam'>
  14. >>> super(Spam, spam).__self__
  15. <__main__.Spam object at 0x107195c10>
  16. >>> super(Spam, spam).__self_class__
  17. <class '__main__.Spam'>
  18.      
  19. >>> super(Spam)
  20. <super: <class 'Spam'>, NULL>
  21. >>> super(Spam).__self__ is None
  22. True
  23. >>> super(Spam).__self_class__ is None
  24. True
  25. >>> super(Spam).bar
  26. Traceback (most recent call last):
  27.   File "<stdin>", line 1, in <module>
  28. AttributeError: 'super' object has no attribute 'bar'
  29.      
  30. >>> super(Spam).__get__(spam, Spam)
  31. <super: <class 'Spam'>, <Spam object>>
  32. >>> super(Spam).__get__(spam, Spam).bar()
  33. 'bar on Foo'
  34.      
  35. >>> class Eggs(Spam):
  36. ...     pass
  37. ...
  38. >>> Eggs.parent = super(Eggs)
  39. >>> eggs = Eggs()
  40. >>> eggs.parent
  41. <super: <class 'Eggs'>, <Eggs object>>
  42. >>> eggs.parent.bar()
  43. 'bar on Spam'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top