PyDocs

Nav

File Formats

ConfigParser.write

  • ConfigParser.write(fileobject, space_around_delimiters=True)
Write an .ini-format representation of the configuration state.

If `space_around_delimiters` is True (the default), delimiters
between keys and values are surrounded by spaces.

Please note that comments in the original configuration file are not
preserved when writing the configuration back.
Changed in 3.14
  • 3.14: Raises InvalidWriteError if this would write a representation which cannot be accurately parsed by a future read() call from this parser.
1 Example
>>> import configparser
>>> config = configparser.ConfigParser()
>>> config['DEFAULT'] = {'ServerAliveInterval': '45',
...                      'Compression': 'yes',
...                      'CompressionLevel': '9'}
>>> config['forge.example'] = {}
>>> config['forge.example']['User'] = 'hg'
>>> config['topsecret.server.example'] = {}
>>> topsecret = config['topsecret.server.example']
>>> topsecret['Port'] = '50022'     # mutates the parser
>>> topsecret['ForwardX11'] = 'no'  # same here
>>> config['DEFAULT']['ForwardX11'] = 'yes'
>>> with open('example.ini', 'w') as configfile:
...   config.write(configfile)
...
from the Python docs
See Also
No see-alsos for configparser/ConfigParser.write
0 Notes
No notes for ConfigParser.write