Portable Settings and App Data Storage, In Python?

拥有回忆 提交于 2019-12-08 03:15:25

问题


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?

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.

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...

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

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

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

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

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?


回答1:


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



来源:https://stackoverflow.com/questions/16275031/portable-settings-and-app-data-storage-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!