Skip to content

Instantly share code, notes, and snippets.

@tbarbugli
Created December 9, 2015 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbarbugli/814f050cfa4990ed89c6 to your computer and use it in GitHub Desktop.
Save tbarbugli/814f050cfa4990ed89c6 to your computer and use it in GitHub Desktop.
def get_class_by_slug(slug):
def get_subclasses(cls):
yield cls
if cls.__subclasses__():
for sub in cls.__subclasses__():
for s in get_subclasses(sub):
yield s
components = {cls.slug: cls for cls in get_subclasses(BaseClass)}
return components[slug]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment