Skip to content

Instantly share code, notes, and snippets.

@marcelor
Created May 26, 2015 20:03
Show Gist options
  • Save marcelor/f0aec90e2f6aa0d97d80 to your computer and use it in GitHub Desktop.
Save marcelor/f0aec90e2f6aa0d97d80 to your computer and use it in GitHub Desktop.
class_for_name
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