Skip to content

Instantly share code, notes, and snippets.

@goliatone
Created November 26, 2013 16:47
Show Gist options
  • Select an option

  • Save goliatone/7661709 to your computer and use it in GitHub Desktop.

Select an option

Save goliatone/7661709 to your computer and use it in GitHub Desktop.
def get_class( kls ):
parts = kls.split('.')
module = ".".join(parts[:-1])
m = __import__( module )
for comp in parts[1:]:
m = getattr(m, comp)
return m
D = get_class("datetime.datetime")
D.now()
"""
"""
get_class = lambda name: reduce(getattr, name.split('.')[1:], __import__(name.partition('.')[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment