summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2011-04-27 16:11:50 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2011-04-27 16:11:50 (GMT)
commit29050d7317f8ea312bcfb9967a307428ce28fc84 (patch)
tree37ad8501754ff8646cc08ca2e964bbc181cb9e41 /Doc/library
parent0abb8b74d911607d8535bd79a042918295627454 (diff)
parentdaab1c80928108a3b2ddf19c0245fe15af1b1fd3 (diff)
downloadcpython-29050d7317f8ea312bcfb9967a307428ce28fc84.zip
cpython-29050d7317f8ea312bcfb9967a307428ce28fc84.tar.gz
cpython-29050d7317f8ea312bcfb9967a307428ce28fc84.tar.bz2
Merged #11670 from 3.2
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/configparser.rst29
1 files changed, 24 insertions, 5 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index cb6f259..fbc593b 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -974,18 +974,37 @@ ConfigParser Objects
.. method:: read_file(f, source=None)
- Read and parse configuration data from the file or file-like object in
- *f* (only the :meth:`readline` method is used). The file-like object
- must operate in text mode. Specifically, it must return strings from
- :meth:`readline`.
+ Read and parse configuration data from *f* which must be an iterable
+ yielding Unicode strings (for example any file object).
Optional argument *source* specifies the name of the file being read. If
not given and *f* has a :attr:`name` attribute, that is used for
*source*; the default is ``'<???>'``.
.. versionadded:: 3.2
- Replaces :meth:`readfp`.
+ Replaces :meth:`readfp`.
+
+ .. note::
+
+ Prior to Python 3.2, :meth:`readfp` consumed lines from the file-like
+ argument by calling its :meth:`~file.readline` method. For existing code
+ calling :meth:`readfp` with arguments which don't support iteration,
+ the following generator may be used as a wrapper around the file-like
+ object::
+ def readline_generator(f):
+ line = f.readline()
+ while line != '':
+ yield line
+ line = f.readline()
+
+ Before::
+
+ parser.readfp(f)
+
+ After::
+
+ parser.read_file(readline_generator(f))
.. method:: read_string(string, source='<string>')