conv_configparser_opts
- opthandler.conv_configparser_opts(config, converter, sections=None, skip_missing_sec=False)[source]
Convert the option names of a
ConfigParser
.- Parameters:
config (
configparser.ConfigParser
) – TheConfigParser
whose option names should be converted.converter (
callable
) – A callable that defines the conversion. Must take a single string as argument.sections (
iterable
orstr
orNone
, optional) – The sections of config whose option names should be converted. IfNone
, convert the option names in all sections.skip_missing_sec (
bool
, optional) – IfTrue
, don’t raise an exception if a given section is not contained in config but instead simply skip this section.
- Returns:
config_converted (
configparser.ConfigParser
) – The inputConfigParser
with converted option names.
See also
conv_configparser_vals()
Convert the values of a
ConfigParser
conv_argparse_opts()
Convert the option names in an
argparse.Namespace
Examples
>>> import configparser >>> config = configparser.ConfigParser() >>> config["Monty"] = {'spam': 'no!', 'eggs': '2'} >>> config["Python"] = {'foo': 'fighter', 'bar': 'baz'} >>> for sec in config.sections(): ... print(sec) ... for opt, val in config.items(sec): ... print(opt, val) Monty spam no! eggs 2 Python foo fighter bar baz >>> config = conv_configparser_opts(config, converter=str.upper) >>> for sec in config.sections(): ... print(sec) ... for opt, val in config.items(sec): ... print(opt, val) Monty SPAM no! EGGS 2 Python FOO fighter BAR baz