Created
April 16, 2020 12:09
-
-
Save vlad-bezden/f5d562da4388e7430a14a07a136fc246 to your computer and use it in GitHub Desktop.
Example of how dynamically invoke function in Python
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 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