我在同一个文件夹中有 python 脚本和 shell 脚本,它们都需要配置。我目前有一个 config.py 用于我的 python 脚本,但我想知道是否有可能有一个配置文件可以很容易地被 python 脚本和 shell 脚本读取。
谁能举出最适合 python 和 shell 读取的配置文件格式的示例。
最佳答案
我认为最简单的解决方案是:
key1="value1"
key2="value2"
key3="value3"
在shell您只需获取此 env 文件的源代码,并且在 Python 中,它很容易解析。
=
对于 Python,请参阅此帖子:Emulating Bash 'source' in Python
关于python - 一个可以被python和shell读取的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441412/