Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> class Foo:
- ... def bar(self):
- ... return 'bar on Foo'
- ...
- >>> class Spam(Foo):
- ... def bar(self):
- ... return 'bar on Spam'
- ...
- >>> spam = Spam()
- >>> super(Spam, spam)
- <super: <class 'Spam'>, <Spam object>>
- >>> super(Spam, spam).__thisclass__
- <class '__main__.Spam'>
- >>> super(Spam, spam).__self__
- <__main__.Spam object at 0x107195c10>
- >>> super(Spam, spam).__self_class__
- <class '__main__.Spam'>
- >>> super(Spam)
- <super: <class 'Spam'>, NULL>
- >>> super(Spam).__self__ is None
- True
- >>> super(Spam).__self_class__ is None
- True
- >>> super(Spam).bar
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'super' object has no attribute 'bar'
- >>> super(Spam).__get__(spam, Spam)
- <super: <class 'Spam'>, <Spam object>>
- >>> super(Spam).__get__(spam, Spam).bar()
- 'bar on Foo'
- >>> class Eggs(Spam):
- ... pass
- ...
- >>> Eggs.parent = super(Eggs)
- >>> eggs = Eggs()
- >>> eggs.parent
- <super: <class 'Eggs'>, <Eggs object>>
- >>> eggs.parent.bar()
- 'bar on Spam'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement