Best way to store config or preferences in a multi-platform way.
M.-A. Lemburg
mal at egenix.com
Thu May 1 08:10:39 EDT 2008
On 2008-05-01 13:37, Lance Gamet wrote:
> Hi, python beginner starting a new project here.
>
> This project will store most of its actual data in a shared-database, but
> I have a small amount of user specific data that I need to be stored like
> configuration or preferences for example, the list of databases that the
> program should connect to.
>
> On Unix this might be a .file, on windows this could be in the registry,
> or an ini file or an xml file in ProgramData or AppData or something.
>
> Is there a pythony way to store such config data, perhaps there is
> already a standard python package for such a purpose?
I don't think this is a Python question, but more a platform
question. Users on different platforms will expect configuration
data in different places. It's usually best to stick to the platform
conventions.
Python has modules available for accessing INI-files, XML-files
and also for the Windows registry, so that part is easy.
> My app uses Qt, and Qt has its method of doing it (QSettings), but for
> architectural reasons I don't want to use it.
>
> Could sqlite be an option perhaps? I am still undecided if the ability
> for the user to edit the file independently of the program is a good or
> bad thing.
If the user is meant to change the data, then you should make this
easy for the user. Putting such data into SQLite will not satisfy that
requirement :-)
If you don't have a GUI tool for the user to change config settings,
then it's probably best to put the configuration into a file that's
easy to edit, e.g. an INI file.
Here's a nice module that supports both reading and writing
INI files:
http://www.voidspace.org.uk/python/configobj.html
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 01 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-list
mailing list