What's the official way of storing settings for python programs?

后端 未结 13 1360
傲寒
傲寒 2020-12-12 23:58

Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.

Are one of these approa

13条回答
  •  感动是毒
    2020-12-13 00:29

    It depends largely on how complicated your configuration is. If you're doing a simple key-value mapping and you want the capability to edit the settings with a text editor, I think ConfigParser is the way to go.

    If your settings are complicated and include lists and nested data structures, I'd use XML or JSON and create a configuration editor.

    For really complicated things where the end user isn't expected to change the settings much, or is more trusted, just create a set of Python classes and evaluate a Python script to get the configuration.

提交回复
热议问题