Python dynamic class names [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Dynamic loading of python modules python: How to add property to a class dynamically? I have a dictionary with the filename and class names how can I import this class names and how can I create this classes? Example: classNames = { 'MCTest':MCTestClass} I want to import the MCTest and create the MCTestClass. 回答1: You have to use the __import__ function: http://docs.python.org/library/functions.html#import