Skip to content

Commit 7151da0

Browse files
committed
Describe the behavior of the read() method when the list of filenames
includes files that do not exist, explain the intended use of the interface, and show how to ensure an expected file really exists. This closes SF bug #490399.
1 parent dfa9787 commit 7151da0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Doc/lib/libcfgparser.tex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ \subsection{ConfigParser Objects \label{ConfigParser-objects}}
135135
\begin{methoddesc}{read}{filenames}
136136
Read and parse a list of filenames. If \var{filenames} is a string or
137137
Unicode string, it is treated as a single filename.
138+
If a file named in \var{filenames} cannot be opened, that file will be
139+
ignored. This is designed so that you can specify a list of potential
140+
configuration file locations (for example, the current directory, the
141+
user's home directory, and some system-wide directory), and all
142+
existing configuration files in the list will be read. If none of the
143+
named files exist, the \class{ConfigParser} instance will contain an
144+
empty dataset. An application which requires initial values to be
145+
loaded from a file should load the required file or files using
146+
\method{readfp()} before calling \method{read()} for any optional
147+
files:
148+
149+
\begin{verbatim}
150+
import ConfigParser, os
151+
152+
config = ConfigParser.ConfigParser()
153+
config.readfp(open('defaults.cfg'))
154+
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
155+
\end{verbatim}
138156
\end{methoddesc}
139157

140158
\begin{methoddesc}{readfp}{fp\optional{, filename}}

0 commit comments

Comments
 (0)