Last active
May 14, 2020 12:13
-
-
Save lig/11caec44202e82983ea44edc67fab41e to your computer and use it in GitHub Desktop.
super() outside of a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class A: | |
... def foo(self): | |
... return 5 | |
>>> class B(A): | |
... def foo(self): | |
... return 3 | |
>>> b = B() | |
>>> super(B, b).foo() | |
5 | |
>>> super(A, b).foo() | |
--------------------------------------------------------------------------- | |
AttributeError Traceback (most recent call last) | |
<ipython-input-6-863be3d3f354> in <module> | |
----> 1 super(A, b).foo() | |
AttributeError: 'super' object has no attribute 'foo' | |
>>> class C(B): | |
... pass | |
>>> c = C() | |
>>> super(B, c).foo() | |
5 | |
>>> A.foo(c) | |
5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment