Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73753d3

Browse files
committed
#6969: make it explicit that configparser writes/reads text files, and fix the example.
1 parent 8355e7c commit 73753d3

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Doc/library/configparser.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ RawConfigParser Objects
231231
.. method:: RawConfigParser.readfp(fp, filename=None)
232232

233233
Read and parse configuration data from the file or file-like object in *fp*
234-
(only the :meth:`readline` method is used). If *filename* is omitted and *fp*
235-
has a :attr:`name` attribute, that is used for *filename*; the default is
236-
``<???>``.
234+
(only the :meth:`readline` method is used). The file-like object must
235+
operate in text mode, i.e. return strings from :meth:`readline`.
236+
237+
If *filename* is omitted and *fp* has a :attr:`name` attribute, that is used
238+
for *filename*; the default is ``<???>``.
237239

238240

239241
.. method:: RawConfigParser.get(section, option)
@@ -279,8 +281,9 @@ RawConfigParser Objects
279281

280282
.. method:: RawConfigParser.write(fileobject)
281283

282-
Write a representation of the configuration to the specified file object. This
283-
representation can be parsed by a future :meth:`read` call.
284+
Write a representation of the configuration to the specified file object,
285+
which must be opened in text mode (accepting strings). This representation
286+
can be parsed by a future :meth:`read` call.
284287

285288

286289
.. method:: RawConfigParser.remove_option(section, option)
@@ -370,7 +373,7 @@ An example of writing to a configuration file::
370373
config.set('Section1', 'foo', '%(bar)s is %(baz)s!')
371374

372375
# Writing our configuration file to 'example.cfg'
373-
with open('example.cfg', 'wb') as configfile:
376+
with open('example.cfg', 'w') as configfile:
374377
config.write(configfile)
375378

376379
An example of reading the configuration file again::

0 commit comments

Comments
 (0)