mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Patch #1212287: fileinput.input() now has a mode parameter for
specifying the file mode input files should be opened with.
This commit is contained in:
parent
67e9fb9d7a
commit
c029f873cb
4 changed files with 51 additions and 15 deletions
|
|
@ -26,8 +26,10 @@ empty. If a filename is \code{'-'}, it is also replaced by
|
|||
it as the first argument to \function{input()}. A single file name is
|
||||
also allowed.
|
||||
|
||||
All files are opened in text mode. If an I/O error occurs during
|
||||
opening or reading a file, \exception{IOError} is raised.
|
||||
All files are opened in text mode by default, but you can override this by
|
||||
specifying the \var{mode} parameter in the call to \function{input()}
|
||||
or \class{FileInput()}. If an I/O error occurs during opening or reading
|
||||
a file, \exception{IOError} is raised.
|
||||
|
||||
If \code{sys.stdin} is used more than once, the second and further use
|
||||
will return no lines, except perhaps for interactive use, or if it has
|
||||
|
|
@ -44,12 +46,14 @@ is present.
|
|||
The following function is the primary interface of this module:
|
||||
|
||||
\begin{funcdesc}{input}{\optional{files\optional{,
|
||||
inplace\optional{, backup}}}}
|
||||
inplace\optional{, backup\optional{, mode}}}}}
|
||||
Create an instance of the \class{FileInput} class. The instance
|
||||
will be used as global state for the functions of this module, and
|
||||
is also returned to use during iteration. The parameters to this
|
||||
function will be passed along to the constructor of the
|
||||
\class{FileInput} class.
|
||||
|
||||
\versionchanged[Added the \var{mode} parameter]{2.5}
|
||||
\end{funcdesc}
|
||||
|
||||
|
||||
|
|
@ -111,7 +115,7 @@ The class which implements the sequence behavior provided by the
|
|||
module is available for subclassing as well:
|
||||
|
||||
\begin{classdesc}{FileInput}{\optional{files\optional{,
|
||||
inplace\optional{, backup}}}}
|
||||
inplace\optional{, backup\optional{, mode}}}}}
|
||||
Class \class{FileInput} is the implementation; its methods
|
||||
\method{filename()}, \method{fileno()}, \method{lineno()},
|
||||
\method{fileline()}, \method{isfirstline()}, \method{isstdin()},
|
||||
|
|
@ -122,6 +126,12 @@ module is available for subclassing as well:
|
|||
which implements the sequence behavior. The sequence must be
|
||||
accessed in strictly sequential order; random access and
|
||||
\method{readline()} cannot be mixed.
|
||||
|
||||
With \var{mode} you can specify which file mode will be passed to
|
||||
\function{open()}. It must be one of \code{'r'}, \code{'rU'},
|
||||
\code{'U'} and \code{'rb'}.
|
||||
|
||||
\versionchanged[Added the \var{mode} parameter]{2.5}
|
||||
\end{classdesc}
|
||||
|
||||
\strong{Optional in-place filtering:} if the keyword argument
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue