在哪里放置用于已编译的Python脚本的配置文件? [英] Where to put a config file for a compiled Python script?
问题描述
这类似于在哪里将配置文件放入Python?,但是我要问的是已编译的脚本/在Windows系统上被py2exe或类似软件冻结。 (即,这是用于用户友好的任意字节字符串的配置文件格式是什么? https://gist.github.com/1119561 )
This is similar to Where to put a configuration file in Python?, but I'm asking about scripts compiled/frozen with py2exe or similar on Windows systems. (Namely, this one: What config file format to use for user-friendly strings of arbitrary bytes? https://gist.github.com/1119561)
我的第一个念头是将配置文件与.exe放在同一文件夹中,这使其具有独立性。但是,如果我将文件与.exe关联,则会从其目录而不是其目录中调用该文件,因此我需要类似如何在Python中获取当前执行文件的路径?查找配置文件。
My first thought was to put the config file in the same folder as the .exe, which makes it sort of self-contained. But if I associate files with the .exe, it will be called from their directory, not its own, so I'd need something like How do I get the path of the current executed file in Python? to find the config file.
这是最好的方法吗?还是有一些标准的配置文件位置可供搜索,例如 https://stackoverflow.com/a/7567946/125507 ?
Is this the best way? Or is there some standard config file locations to search in, like https://stackoverflow.com/a/7567946/125507 ?
推荐答案
您可以使用 appdirs模块来确定用于用户数据的适当文件夹。
You can use the appdirs module to determine the appropriate folder for user data.
这篇关于在哪里放置用于已编译的Python脚本的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!