Skip to content

Instantly share code, notes, and snippets.

@echiesse
Created March 4, 2022 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echiesse/7de4e630c6d6bc59d567a3efc4bb04cd to your computer and use it in GitHub Desktop.
Save echiesse/7de4e630c6d6bc59d567a3efc4bb04cd to your computer and use it in GitHub Desktop.
Example of altering a class in runtime
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