Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save application settings in a config file?

I am developing a program that has a settings window in which I can change various parameters for my program. What is the best way to read/save them in some kind of config file? I know that some software and games use .ini files or similar system. How can I achieve this in Python?

like image 519
Domagoj Avatar asked Apr 13 '13 20:04

Domagoj


3 Answers

The Python standard library includes the ConfigParser module, which handles ini-style configuration files for you. It's more than adequate for most uses.

like image 112
Cairnarvon Avatar answered Sep 29 '22 21:09

Cairnarvon


Another popular option for configuration files is JSON - it's a simple notation which has good support from a wide range of languages.

Python has the json module in the standard library, which makes it very easy.

like image 41
Gareth Latty Avatar answered Sep 29 '22 20:09

Gareth Latty


Since you introduced the term config file in your question, the previous answers concentrated on means for creating plain text files, which also could be manipulated using a standard text editor. Depending on the sort of settings to store this might not be desired, since it requires strict plausibility checks after reading back the config file at the very least. So I add the proposal of the shelves module which is a straight-forward way to make information persistent in files.

like image 45
guidot Avatar answered Sep 29 '22 20:09

guidot