Python - configuration options, how to enter / process?

When your application takes several (~ 5) configuration parameters, and the application is used by users who do not use technology (i.e. KISS ), how do you usually handle reading configuration parameters, and then bypass parameters between objects / functions (several modules) ?

Examples of options: I / O directories / file names, level of detail.

I usually use optparse(Python) and bypass parameters / parameters as arguments; but I wonder if it is more common to use a configuration text file that is read directly by the objects of all modules (but then is it not so, for example, to have "global" variables ?, and without "owning" the state?).

Another common problem is unit testing; if I want to unit test each individual module, a separate module may require only 1 of 5 configuration options; how do you usually separate individual modules / objects from the rest of the application, and still allow to accept 1 or 2 required parameters (is it really possible to call the unit test structure or use the configuration functions)?

I suppose that there is not the only right way to do this, but it would be interesting to read about various approaches or well-known patterns.

+3
source share
2 answers
"Counts answer"
Please update these counts and feel free to add/modify.

Do you usually read config options via:
- command-line/gui options : 1
- a config text file       : 0


How do multiple modules/objects have access to these options?
- they receive them from the caller as an argument: 1
- read them directly from the config text file:     0


When doing unit-testing of a single module (NOT the "main" module)
and the module uses one option, e.g. input filename:
- unit-test framework provides own "simplified" config functionality: 0
- unit-test framework invokes main app config functionality:        1


Do you use:
- optparse:  1
- getopt:    0
- others?


Please list any config management "design pattern" 
(usable in Python) and add a count if you use it - thanks.
- 
-
0
source

: - /gui -

. Django settings.py logging.ini. .

/ ?

  • settings.py; logging.ini - .
  • .

[ optparse - .]

( "" ): (, , )

[ . , " , ?" ]

- . , , . " 1 5 ". ( ) .

optparse.

+2

Source: https://habr.com/ru/post/1710869/


All Articles