Skip to content

Instantly share code, notes, and snippets.

@piotch
Last active August 29, 2015 14:11
Show Gist options
  • Save piotch/0248c81585f178a52451 to your computer and use it in GitHub Desktop.
Save piotch/0248c81585f178a52451 to your computer and use it in GitHub Desktop.
Load a class from its dotted path
from importlib import import_module
_module = lambda x: x[:x.rfind('.')]
_cls = lambda x: x[x.rfind('.')+1:]
s = 'some.module.class'
getattr(import_module(_module(s)), _cls(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment