summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-29 12:17:40 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-29 12:17:40 (GMT)
commit8dcaa7396fd89ec84a29ae90c7958d0618ee6c62 (patch)
tree5b4826c5b8c2ba9aac9395f65523b287ab91a79d /Doc/library
parentf206d0e3931b64aa3c8219badb9e0fbb81f1eb38 (diff)
downloadcpython-8dcaa7396fd89ec84a29ae90c7958d0618ee6c62.zip
cpython-8dcaa7396fd89ec84a29ae90c7958d0618ee6c62.tar.gz
cpython-8dcaa7396fd89ec84a29ae90c7958d0618ee6c62.tar.bz2
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/configparser.rst28
1 files changed, 16 insertions, 12 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 792784b..f77a5b8 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -286,25 +286,29 @@ RawConfigParser Objects
:const:`True`; otherwise return :const:`False`.
-.. method:: RawConfigParser.read(filenames)
+.. method:: RawConfigParser.read(filenames, encoding=None)
Attempt to read and parse a list of filenames, returning a list of filenames
- which were successfully parsed. If *filenames* is a string,
- it is treated as a single filename. If a file named in *filenames* cannot be
- opened, that file will be ignored. This is designed so that you can specify a
- list of potential configuration file locations (for example, the current
- directory, the user's home directory, and some system-wide directory), and all
- existing configuration files in the list will be read. If none of the named
- files exist, the :class:`ConfigParser` instance will contain an empty dataset.
- An application which requires initial values to be loaded from a file should
- load the required file or files using :meth:`readfp` before calling :meth:`read`
- for any optional files::
+ which were successfully parsed. If *filenames* is a string, it is treated as
+ a single filename. If a file named in *filenames* cannot be opened, that
+ file will be ignored. This is designed so that you can specify a list of
+ potential configuration file locations (for example, the current directory,
+ the user's home directory, and some system-wide directory), and all existing
+ configuration files in the list will be read. If none of the named files
+ exist, the :class:`ConfigParser` instance will contain an empty dataset. An
+ application which requires initial values to be loaded from a file should
+ load the required file or files using :meth:`readfp` before calling
+ :meth:`read` for any optional files::
import configparser, os
config = configparser.ConfigParser()
config.readfp(open('defaults.cfg'))
- config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
+ config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')], encoding='cp1250')
+
+ .. versionadded:: 3.2
+ The *encoding* parameter. Previously, all files were read using the
+ default encoding for :func:`open`.
.. method:: RawConfigParser.readfp(fp, filename=None)