How to save application settings in a config file?

巧了我就是萌 提交于 2019-11-27 15:08:20

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/15992387/how-to-save-application-settings-in-a-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!