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

后端 未结 13 1339
傲寒
傲寒 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:13

    For web applications I like using OS environment variables: os.environ.get('CONFIG_OPTION')

    This works especially well for settings that vary between deploys. You can read more about the rationale behind using env vars here: http://www.12factor.net/config

    Of course, this only works for read-only values because changes to the environment are usually not persistent. But if you don't need write access they are a very good solution.

提交回复
热议问题