Created
May 26, 2015 20:03
-
-
Save marcelor/f0aec90e2f6aa0d97d80 to your computer and use it in GitHub Desktop.
class_for_name
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
import importlib | |
def class_for_name(module_name, class_name): | |
# load the module, will raise ImportError if module cannot be loaded | |
m = importlib.import_module(module_name) | |
# get the class, will raise AttributeError if class cannot be found | |
c = getattr(m, class_name) | |
return c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment