I want to import a class from python module. The module contains multiple classes and which one I need is determined by a string at runtime.
Edit: I'm using python 2.6.5, django 1.3.
明智地使用getattr()
。
MyClass = getattr(mymodule, myclass_name)
或者导入 (module,globals(),locals(),['classname',], - 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.