How to configure python environment configuration

In recent years, I have mainly used django. Django uses an environment variable DJANGO_SETTINGS_MODULEto find its configuration.

Now I have a project in which I am not using django, and I would like to have a simple and clear way to load the configuration.

Example:

I want the global boolean to enable or disable debugging:

settings.DEBUG

I think there are thousands of ways to do this.

But what is the most pythonic way to store and load project settings?

... perhaps the Python community has already settled on the well-known standard method that I don't know yet.

+4
source share
2 answers

: https://docs.python.org/2/library/constants.html

__debug__

, Python -O.

, logging.setLevel(lvl): https://docs.python.org/2/library/logging.html#logging.Logger.setLevel

Update:

singleton, .. , . config.py

DEBUG = False
OTHER_THING = True

import config
print(config.DEBUG)
+2

-, ConfigParser. , , (, JSON).

, , , logging.

logging ConfigParser . , .

+1

All Articles