通过字符串导入从模块导入*

通过字符串导入从模块导入*,第1张

通过字符串导入模块导入*

这是一个解决方案:导入模块,然后在当前名称空间中一个接一个地创建别名

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)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5631478.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存