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) – TheConfigParserwhose option names should be converted.converter (
callable) – A callable that defines the conversion. Must take a single string as argument.sections (
iterableorstrorNone, 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 inputConfigParserwith converted option names.
See also
conv_configparser_vals()Convert the values of a
ConfigParserconv_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