我得到了2个python文件implement test repository工厂模式:
在测试库.py在class TestRepository(object):
def __init__(self):
pass
def generate(self, username, password):
pass
def update(self):
pass
class RepositoryFactory(object):
factories = {}
def add_repo(identification, repo_factory):
RepositoryFactory.factories[identification] = repo_factory
add_repo = staticmethod(add_repo)
def create_repo(identification, server, dirpath, reponame):
if identification not in RepositoryFactory.factories:
RepositoryFactory.factories[identification] = \
eval(identification + '.Factory()')
return RepositoryFactory.factories[identification].create(server, dirpath, reponame)
create_repo = staticmethod(create_repo)
在gitrepository.py在
^{pr2}$
问题是repo_type=TestRepository。上面示例中的\uu子类是空的,如果我将所有类放在一个文件中,它就可以工作了:>>> print TestRepository.__subclasses__()
[]
所以问题是如何从几个python模块中获取所有子类?在