Skip to content

Instantly share code, notes, and snippets.

@cypreess
Last active June 29, 2018 09:07
Show Gist options
  • Select an option

  • Save cypreess/029ad411937d86d65690f9e06cb89c93 to your computer and use it in GitHub Desktop.

Select an option

Save cypreess/029ad411937d86d65690f9e06cb89c93 to your computer and use it in GitHub Desktop.
Import specific class in Python
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