configparser example typo
To whom it may concern, In the page https://docs.python.org/3/library/configparser.html, under 14.2.1 Quick Start, example 2 with code:
import configparser>>> config = configparser.ConfigParser()>>> config['DEFAULT'] = {'ServerAliveInterval': '45',... 'Compression': 'yes',... 'CompressionLevel': '9'}>>> config['bitbucket.org'] = {}>>> config['bitbucket.org']['User'] = 'hg'>>> config['topsecret.server.com'] = {}>>> topsecret = config['topsecret.server.com']>>> 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)...
Shouldn't the last line be configfile.write(config) ? Weihe
On Tue, Jul 10, 2018 at 10:24 AM Weihe Chen <wec3217@gmail.com> wrote:
In the page https://docs.python.org/3/library/configparser.html, under 14.2.1 Quick Start, example 2 with code: ... Shouldn't the last line be configfile.write(config) ?
No; the example is correct. The config object provides a write method that knows how to format the configuration data and write it to an open file passed as an argument. -Fred -- Fred L. Drake, Jr. <fred at fdrake.net> "A storm broke loose in my mind." --Albert Einstein
participants (2)
-
Fred Drake
-
Weihe Chen