How to instantiate a class given its name as a string?
This question already has an answer here:
Considering that the Python naming scheme is based on maps, you will be using maps of one sort or another even if you use eval
.
Building your own map is the most appropriate, but you can also use globals()
or retrieve it from a module if your classes are stored somewhere else:
import util_module
getattr(util_module, 'A') ()
链接地址: http://www.djcxy.com/p/55178.html
上一篇: 使用Python映射和其他功能工具
下一篇: 如何实例化一个给定其名称为字符串的类?