e3fp.config.params module

Get E3FP default parameters and read parameters from files.

Author: Seth Axen E-mail: seth.axen@gmail.com

get_default_value(*args, **kwargs)[source]
get_value(params, section_name, param_name, dtype=<class 'str'>, auto=False, fallback=None)[source]

Get value from params with fallback.

Parameters
  • params (ConfigParser) – Parameters

  • section_name (str) – Name of section in params

  • param_name (str) – Name of parameter in section

  • dtype (type, optional) – Type to return data as.

  • auto (bool, optional) – Auto-discover type of value. If provided, dtype is ignored.

  • fallback (any, optional) – Value to return if getting value fails.

Returns

value – Value of parameter or fallback.

Return type

any

params_to_sections_dict(params, auto=True)[source]

Get dict of sections dicts in params, with optional type discovery.

Parameters
  • params (str or ConfigParser) – Params to read

  • auto (bool, optional) – Auto typing of parameter values.

Returns

dict

Return type

dict matching sections to parameters to values.

read_params(params=None, fill_defaults=False)[source]

Get combination of provided parameters and default parameters.

Parameters
  • params (str or ConfigParser, optional) – User provided parameters as an INI file or ConfigParser. Any parameters provided will replace default parameters.

  • fill_defaults (bool, optional) – Fill values that aren’t provided with package defaults, if params is file.

Returns

all_params – Combination of default and user-provided parameters.

Return type

ConfigParser

update_params(params_dict, params=None, section_name=None, fill_defaults=False)[source]

Set ConfigParser values from a sections dict.

Sections dict key must be parameter sections, and value must be dict matching parameter name to value. If existing ConfigParser is provided, parameter values are updated.

Parameters
  • params_dict (dict) – If section_name is provided, dict must match parameter names to values. If section_name is not provided, dict key(s) must be parameter sections, and value(s) must be parameter dict.

  • params (ConfigParser, optional) – Existing parameters.

  • section_name (str, optional) – Name of section to which to add parameters in params_dict

  • fill_defaults (bool, optional) – Fill values that aren’t provided with package defaults, if params is file.

write_params(params, params_file='params.cfg')[source]

Write params to file.

Parameters
  • params (ConfigParser) – Params

  • params_file (str) – Params file