PyDocs

Nav

File Formats

ConfigParser

  • ConfigParser(defaults=None, dict_type=dict, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={}, allow_unnamed_section=False)
ConfigParser implementing interpolation.
Changed in 3.1, 3.2, 3.5, 3.7, 3.8, 3.13
  • 3.1: The default dict_type is collections.OrderedDict.
  • 3.2: allow_no_value, delimiters, comment_prefixes, strict, empty_lines_in_values, default_section and interpolation were added.
  • 3.5: The converters argument was added.
  • 3.7: The defaults argument is read with read_dict(), providing consistent behavior across the parser: non-string keys and values are implicitly converted to strings.
  • 3.8: The default dict_type is dict, since it now preserves insertion order.
  • 3.13: Raise a MultilineContinuationError when allow_no_value is True, and a key without a value is continued with an indented line.
  • 3.13: The allow_unnamed_section argument was added.
Members of ConfigParser

a

add_section
Create a new section in the configuration.

b

BOOLEAN_STATES
By default when using getboolean(), config parsers consider the following values True: '1', 'yes', 'true', 'on' and the following values False: '0', 'no', 'false', 'off'.

d

defaults
Return a dictionary containing the instance-wide defaults.

g

get
Get an option value for a given section.
getboolean
A convenience method which coerces the option in the specified section to a Boolean value.
getfloat
A convenience method which coerces the option in the specified section to a floating-point number.
getint
A convenience method which coerces the option in the specified section to an integer.

h

has_option
Check for the existence of a given option in a given section.
has_section
Indicate whether the named section is present in the configuration.

i

items
Return a list of (name, value) tuples for each option in a section.

o

options
Return a list of option names for the given section name.
optionxform
Transforms the option name option as found in an input file or as passed in by client code to the form that should be used in the internal structures.

r

read
Read and parse a filename or an iterable of filenames.
read_dict
Read configuration from a dictionary.
read_file
Like read() but the argument must be a file-like object.
read_string
Read configuration from a given string.
remove_option
Remove an option.
remove_section
Remove a file section.

s

SECTCRE
A compiled regular expression used to parse section headers.
sections
Return a list of section names, excluding [DEFAULT]
set
Set an option.

w

write
Write an .ini-format representation of the configuration state.
1 Example
>>> config_override = configparser.ConfigParser()
>>> config_override['DEFAULT'] = {'ServerAliveInterval': '-1'}
>>> with open('override.ini', 'w') as configfile:
...     config_override.write(configfile)
...
>>> config_override = configparser.ConfigParser()
>>> config_override.read(['example.ini', 'override.ini'])
['example.ini', 'override.ini']
>>> print(config_override.get('DEFAULT', 'ServerAliveInterval'))
-1
from the Python docs
See Also
No see-alsos for configparser/ConfigParser
0 Notes
No notes for ConfigParser