python - 一个可以被python和shell读取的配置文件

标签 python bash shell configuration debian

我在同一个文件夹中有 python 脚本和 shell 脚本,它们都需要配置。我目前有一个 config.py 用于我的 python 脚本,但我想知道是否有可能有一个配置文件可以很容易地被 python 脚本和 shell 脚本读取。

谁能举出最适合 python 和 shell 读取的配置文件格式的示例。

最佳答案

我认为最简单的解决方案是:

key1="value1"
key2="value2"
key3="value3"

您只需获取此 env 文件的源代码,并且在 Python 中,它很容易解析。

=

两边不允许有空格

对于 Python,请参阅此帖子:Emulating Bash 'source' in Python

关于python - 一个可以被python和shell读取的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441412/

相关文章:

python - flake8:导入语句顺序错误

shell - 在不退出 hive shell 的情况下终止 hive 查询

linux - shell语言的数据组

node.js - 临时别名命令以压缩现有命令,然后在脚本退出时过期

linux - 脚本中的 ejabberdctl 命令给出错误 "Connection attempt from disallowed node"

linux - 当 i/p 从文件重定向时读取不提示

为多个文件调用 fgets 两次

python - 如何在 Python 中打印特定的 JSON 值?

python - 堆叠稀疏和密集矩阵

python - pip install Pygame 后导入 Pygame 时出现 ModuleNotFoundError