tags:

views:

50

answers:

2

I have a python module which contains a few objects, one of which uses a MySQL connection to persist some data. What's the best way to allow for easy configuration of the MySQL connection information without making the user go into the installed module location and edit files?

+2  A: 

You could pull the configuration details for MySQL from an .ini file using ConfigParser.

John Paulett
+4  A: 

Allow the user to write configuration information for the program in a file of the format that ConfigParser knows how to parse -- this way, the user doesn't have to "go into the installed module location" but can edit the configuration file in more convenient places.

It is traditional and helpful for the program to attempt to read both a "per-user" configuration file (in the user's home directory or subdir thereof), and a "per-location" configuration file that a system administrator could use to provide the users with some defaults; so, the read method of config parser objects accepts a list of filenames and tries to parse each of them in sequence (see the simple example in the docs I'm pointing to).

Alex Martelli
Think that'd be better than just mandating that the user have a my.cnf file in their home directory? If the only configuration that exists is MySQL connection information.
Wells
Well, no- I guess you don't really store host names in my.cnf files..
Wells
@Wells, I just believe in making the user's life easy (when I can without going crazy myself;-) -- on a typical single-user machine it may not matter much, but even there it might (maybe the knowledgeable friend or relative that sets up the machine for the not-so-knowledgeable owner/user thereof appreciates the ability to stash some config info where the bumbling owner of the machine is less likely to mess it up;-).
Alex Martelli