Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created April 16, 2020 12:09
Show Gist options
  • Save vlad-bezden/f5d562da4388e7430a14a07a136fc246 to your computer and use it in GitHub Desktop.
Save vlad-bezden/f5d562da4388e7430a14a07a136fc246 to your computer and use it in GitHub Desktop.
Example of how dynamically invoke function in Python
class Cleaner:
@classmethod
def clean(cls, type, *args, **kwargs):
getattr(cls, f"_clean_{type}")(*args, **kwargs)
@classmethod
def _clean_email(cls, *args, **kwargs):
print("invoked _clean_email function")
@classmethod
def _clean_name(cls, *args, **kwargs):
print("invoked _clean_name function")
for type in ["email", "name"]:
Cleaner.clean(type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment