# -*- coding: utf-8 -*-
from importlib import import_module
import pdb
module = import_module("test2")
test_class = getattr(module, "Test") # 类
test_instance = test_class() # 实例化
print dir(test_instance)
pdb.set_trace()
两个文件
代码为test1.py中的内容。
test2.py为引用的库,包含Test类。没有实例化参数。
class Test(object):
def __init__(self):
pass