How to instantiate class by it's string name in Python from CURRENT file? [duplicate]
问题 This question already has answers here : Instantiate a Python class from a name [duplicate] (6 answers) Closed 2 years ago . Suppose I have myfile.py with some classes A , B and C defined INSIDE it. Now I want to instantiate class by it's name in str. I don't understand what to pass to getattr in order to do this. All examples like this assume that classes are in other module: module = __import__(module_name) class_ = getattr(module, class_name) instance = class_() but I don't have module