读取conf文件并使内容可供包中的所有文件使用
myMain.py
/myPackage
file1.py
file2.py
confFile.cfg
myMain.py 导入 file1 和 file2 等并读取 confFile。 使conf选项可见的最佳方式是什么 整个包裹?即 file1 和 file2 能够读取 conf 选项。我不想传递很多变量 在函数中。
我现在拥有的是一个confFile.py,我将其导入到文件中 并根据需要读取从中定义的变量。
我是 python 新手,如有任何建议,我们将不胜感激。
/扎尔
myMain.py
/myPackage
file1.py
file2.py
confFile.cfg
myMain.py imports file1 and file2 etc. and it reads the confFile.
what would be the best way for the conf options to be visible in
the whole package? i.e. for file1 and file2 to be able to read
the conf options. I do not want to pass a lot of variables around
in functions.
What I have right now is a confFile.py which i import into the files
and read the variables defined from it as they are required.
I am new to python and any suggestions are appreciated.
/Zaar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好的方法是只拥有一个 python 模块 config.py 或 settings.py 并将这些设置直接存储在这些 python 文件中而不是 confFile 中。 cfg。
然后你就可以通过以下方式获得你想要的任何东西:
I think the best way is to just have a python module
config.py
orsettings.py
and store those settings directly in those python files instead of theconfFile.cfg
.Then you could just get anything you want by: