Created
November 22, 2024 19:40
-
-
Save swo/4c641bdfbd9d805d42542d7c7290fd0b to your computer and use it in GitHub Desktop.
Python `__super__` calls
This file contains hidden or 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 MyClass: | |
def __init__(self): | |
self.report() | |
def report(self): | |
print("Initializing MyClass") | |
class MySubClass(MyClass): | |
def __init__(self): | |
super().__init__() | |
self.report() | |
def report(self): | |
print("Initializing MySubClass") | |
if __name__ == "__main__": | |
MyClass() | |
# this prints "Initializing MyClass" | |
MySubClass() | |
# this prints "Initializing MySubClass" twice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment