Created
March 4, 2022 22:02
-
-
Save echiesse/7de4e630c6d6bc59d567a3efc4bb04cd to your computer and use it in GitHub Desktop.
Example of altering a class in runtime
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 p(self): | |
print("função A.p") | |
if __name__ == '__main__': | |
a = A() | |
a.p() | |
try: | |
a.f() | |
except: | |
print("A função A.f não existe") | |
# Alterando a classe A dinamicamente | |
def f(self): | |
print('função A.f') | |
A.f = f | |
a.f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment