Last active
June 29, 2018 09:07
-
-
Save cypreess/029ad411937d86d65690f9e06cb89c93 to your computer and use it in GitHub Desktop.
Import specific class 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
| def import_name(name): | |
| components = name.split('.') | |
| mod = __import__( | |
| '.'.join(components[0:-1]) | |
| ) | |
| for m in components[1:]: | |
| mod = getattr(mod, m) | |
| return mod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment