这是一个解决方案:导入模块,然后在当前名称空间中一个接一个地创建别名:
import importlib# import the modulemod = importlib.import_module('collections')# Determine a list of names to copy to the current name spacenames = getattr(mod, '__all__', [n for n in dir(mod) if not n.startswith('_')])# Copy those names into the current name spaceg = globals()for name in names: g[name] = getattr(mod, name)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)