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 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

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, 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;-).
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.