这与Where to put a configuration file in Python?类似,但我在Windows系统上询问有关使用py2exe编译/冻结的类似脚本。 (即,这一个:What config file format to use for user-friendly strings of arbitrary bytes?https://gist.github.com/1119561)在哪里放置一个编译的Python脚本的配置文件?
我的第一个想法是将配置文件放在与.exe相同的文件夹,这使得它的自足。但是,如果我将文件与.exe关联起来,它将从它们的目录中调用,而不是它自己的,所以我需要类似How do I get the path of the current executed file in Python?来查找配置文件。
这是最好的方法吗?还是有一些标准的配置文件位置进行搜索,如https://stackoverflow.com/a/7567946/125507?
不,这是行不通的。 'os.getcwd()'返回双击文件所在的目录,而不是脚本所在的目录。 – endolith 2012-03-19 04:01:13
我猜这样的标准放置位置可能在%appdata%目录中? – 2012-03-19 05:29:47