initializing "parameters" class in Python only once?

Ben Finney ben at benfinney.id.au
Tue Jul 15 02:04:05 CEST 2014


Catherine M Moroney <Catherine.M.Moroney at jpl.nasa.gov> writes:

> The problem:  I'm writing a large Python program and I have a bunch of
> parameters (whose values are static) that I want to make available to
> the rest of the code with minimum overhead and duplicate processing.

Better than putting these in executable code, then, is to put them in a
configuration file read as *data*, not code, when your program starts.

Look at the ‘configparser’ module from the Python standard library
<URL:https://docs.python.org/3/library/configparser.html> for a robust
way to read run-time configuration parameters from a non-executable file.

The result of reading the config file (or set of them, if your use case
is complex enough) is an object containing the parameters, which can be
interrogated as normal by getting its attributes. See the documentation
for examples.

-- 
 \            “[T]he great menace to progress is not ignorance but the |
  `\           illusion of knowledge.” —Daniel J. Boorstin, historian, |
_o__)                                                        1914–2004 |
Ben Finney




More information about the Python-list mailing list