سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top