Skip to content

Instantly share code, notes, and snippets.

@swo
Created November 22, 2024 19:40
Show Gist options
  • Save swo/4c641bdfbd9d805d42542d7c7290fd0b to your computer and use it in GitHub Desktop.
Save swo/4c641bdfbd9d805d42542d7c7290fd0b to your computer and use it in GitHub Desktop.
Python `__super__` calls
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