0
让我们假设你有一个名为“module”的模块在雇佣主体“folder2”中,并且有一个名为“klass”的类。如何从Python中的前一个__import__中获取类对象/实例?
我怎样才能得到像方括号语法的类?
module = __import__('folder1.folder2.module', fromlist='*')
sbs_module = module['klass']
#lets say we print a value from the method getValue
print sbs_module.getValue()
我做到了按属性: 模块= __import __( 'folder1.folder2.module',fromlist里= '*') 克拉斯= GETATTR(模块, '克拉斯') 打印klass.getValue() 和它的工作, 谢谢。 – Uuid