可移植设置和应用程序数据存储,使用Python? [英] Portable Settings and App Data Storage, In Python?

查看:110
本文介绍了可移植设置和应用程序数据存储,使用Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是可移植的方式来存储本地运行的(桌面)python程序的设置和生成的应用程序数据?是否有一些pythonic正确的方法或广泛使用的第三方模块?

What is a portable way to store settings and generated app data for locally-run (desktop) python programs? Is there some pythonic right-way or a widely used 3rd party module?

理想情况下,我希望以某种可移植的方式将OS X的默认系统和Windows的System.Configuration系统绑定在一起.我会寻找一种方法来获取正确的路径来存储用户操作系统的持久性设置数据.

Ideally I want some portable way to tie into OS X's defaults system and Windows' System.Configuration system. I'd settle for a way to get the right path to store persistent settings data for the user's OS.

我了解sqlite/pickle/ConfigParser/json/shelve/dbm等各种相关技术,但我还没有找到一种可移植的方法来确定用户操作系统和安装的正确 place 情况...

I know about the various relevant technologies like sqlite/pickle/ConfigParser/json/shelve/dbm, but I haven't found a portable way to determine the right place for the user's OS and installation circumstances...

例如,在Win XP/2000上,可能是: C:\Documents and Settings\<Windows login>\Application Data\<some app identifier>\

For example on Win XP/2000 it would probably be: C:\Documents and Settings\<Windows login>\Application Data\<some app identifier>\

在Windows Vista和Windows 7上可能是: C:\Users\<Windows login/user name>\AppData\Roaming\<some app identifier>\

On Windows Vista and Windows 7 it would probably be: C:\Users\<Windows login/user name>\AppData\Roaming\<some app identifier>\

在大多数类似Unix的操作系统上,可能是: ~/.<some app identifier>/

On most Unix-like operating systems it would probably be: ~/.<some app identifier>/

在Mac OS X上可能是: ~/Library/Application Support/<some app identifier>

On Mac OS X it would probably be: ~/Library/Application Support/<some app identifier>

我对winpaths(来自pypi)很熟悉,但似乎仅是Windows.您是否总是使用os.path将点文件放在用户的主目录中并希望获得最好的结果?

I'm familiar with winpaths (from pypi), but it seems to be windows only. Do you just always use os.path to put a dot file in a users' home directory and hope for the best?

推荐答案

PyPi上有一个 appdirs模块应该以可移植的方式解决此问题.

There is an appdirs module on PyPi that should solve this in a portable way.

这篇关于可移植设置和应用程序数据存储,使用Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆