我应该如何在 ~/.config 或类似文件中创建和读取用户可编辑的配置文件? [英] How should I create and read a user editable configuration file in ~/.config or similar?
问题描述
我正在计划一个命令行 Python 应用程序,我打算通过 PyPi 分发它.
I am planning a command line Python application that I intend to distribute through PyPi.
当使用 pip 安装应用程序时,我想在用户文件系统的适当位置创建一个用户可编辑的配置文件.
When the application is installed with pip, I want to create a user-editable configuration file in the appropriate location on the user's filesystem.
例如,在 Ubuntu 中,文件类似于 ~/.config/foo/config.ini
For example, in Ubuntu, the file would be something like ~/.config/foo/config.ini
在安装时,我想创建文件(如果可能)并能够指定另一个配置文件来代替命令行参数.
On installation I want to create the file (if possible) and be able to specify another config file to use instead with a command line parameter.
完成这项工作的常用方案是什么?
What is the usual scheme for getting this done?
推荐答案
我认为 PyPI 上的 appdirs
包是您所需要的,不是吗?
I think appdirs
package on PyPI is what you need, isn’t it?
这篇关于我应该如何在 ~/.config 或类似文件中创建和读取用户可编辑的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!