Skip to content

Instantly share code, notes, and snippets.

@shubhamagarwal92
Created July 22, 2019 21:57
Show Gist options
  • Save shubhamagarwal92/84a468c70ac71dace067126ac18496b9 to your computer and use it in GitHub Desktop.
Save shubhamagarwal92/84a468c70ac71dace067126ac18496b9 to your computer and use it in GitHub Desktop.
Call a class by using its name as string
# Also refer https://stackoverflow.com/a/1176225
import sys
class Foobar:
pass
def str_to_class(str):
return getattr(sys.modules[__name__], str)
str_to_class("Foobar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment