python脚本需要按用户配置来覆盖(重新定义)“默认”分配(例如path = "local/path/"
),这可以通过使用导入自定义模块的属性来完成from custom_settings import *
。我想输出自定义模块正在更改的内容。
从内custom_settings
它的属性可以被获得dir()
,例如", ".join( (a for a in dir() if not a.startswith("__") ) )
。如果将导入的模块属性绑定到现有名称空间,该如何从导入脚本中完成?
这可能不是最整洁的解决方案,而且看起来很多余,但是您可以始终简单地进行以下操作:
from custom_settings import *
import custom_settings
overridden = ", ".join(a for a in dir(custom_settings) if not a.startswith("__"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句