diff options
Diffstat (limited to 'Doc/library/io.rst')
-rw-r--r-- | Doc/library/io.rst | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 2a3ee50..d8a498b 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -51,7 +51,7 @@ Module Interface classes. :func:`open` uses the file's blksize (as obtained by :func:`os.stat`) if possible. -.. function:: open(file[, mode[, buffering[, encoding[, errors[, newline[, closefd=True]]]]]]) +.. function:: open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True) Open *file* and return a corresponding stream. If the file cannot be opened, an :exc:`IOError` is raised. @@ -250,7 +250,7 @@ I/O Base Classes Return ``True`` if the stream can be read from. If False, :meth:`read` will raise :exc:`IOError`. - .. method:: readline([limit]) + .. method:: readline(limit=-1) Read and return one line from the stream. If *limit* is specified, at most *limit* bytes will be read. @@ -259,13 +259,13 @@ I/O Base Classes the *newlines* argument to :func:`open` can be used to select the line terminator(s) recognized. - .. method:: readlines([hint]) + .. method:: readlines(hint=-1) Read and return a list of lines from the stream. *hint* can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds *hint*. - .. method:: seek(offset[, whence]) + .. method:: seek(offset, whence=SEEK_SET) Change the stream position to the given byte *offset*. *offset* is interpreted relative to the position indicated by *whence*. Values for @@ -292,7 +292,7 @@ I/O Base Classes Return the current stream position. - .. method:: truncate([size]) + .. method:: truncate(size=None) Truncate the file to at most *size* bytes. *size* defaults to the current file position, as returned by :meth:`tell`. @@ -317,7 +317,7 @@ I/O Base Classes In addition to the attributes and methods from :class:`IOBase`, RawIOBase provides the following methods: - .. method:: read([n]) + .. method:: read(n=-1) Read and return all the bytes from the stream until EOF, or if *n* is specified, up to *n* bytes. Only one system call is ever made. An empty @@ -375,7 +375,7 @@ I/O Base Classes .. versionadded:: 3.1 - .. method:: read([n]) + .. method:: read(n=-1) Read and return up to *n* bytes. If the argument is omitted, ``None``, or negative, data is read and returned until EOF is reached. An empty bytes @@ -390,7 +390,7 @@ I/O Base Classes A :exc:`BlockingIOError` is raised if the underlying raw stream has no data at the moment. - .. method:: read1([n]) + .. method:: read1(n=-1) Read and return up to *n* bytes, with at most one call to the underlying raw stream's :meth:`~RawIOBase.read` method. @@ -419,7 +419,7 @@ I/O Base Classes Raw File I/O ------------ -.. class:: FileIO(name[, mode]) +.. class:: FileIO(name, mode='r', closefd=True) :class:`FileIO` represents a file containing bytes data. It implements the :class:`RawIOBase` interface (and therefore the :class:`IOBase` @@ -443,7 +443,7 @@ Raw File I/O The file name. This is the file descriptor of the file when no name is given in the constructor. - .. method:: read([n]) + .. method:: read(n=-1) Read and return at most *n* bytes. Only one system call is made, so it is possible that less data than was requested is returned. Use :func:`len` @@ -490,7 +490,7 @@ Buffered Streams current stream position, as returned by :meth:`tell`. -.. class:: BufferedReader(raw[, buffer_size]) +.. class:: BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE) A buffer for a readable, sequential :class:`RawIOBase` object. It inherits :class:`BufferedIOBase`. @@ -522,7 +522,7 @@ Buffered Streams Otherwise, one raw stream read call is made. -.. class:: BufferedWriter(raw[, buffer_size[, max_buffer_size]]) +.. class:: BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE) A buffer for a writeable sequential RawIO object. It inherits :class:`BufferedIOBase`. @@ -531,7 +531,7 @@ Buffered Streams *raw* stream. If the *buffer_size* is not given, it defaults to :data:`DEFAULT_BUFFER_SIZE`. - *max_buffer_size* is unused and deprecated. + A third argument, *max_buffer_size*, is supported, but unused and deprecated. :class:`BufferedWriter` provides or overrides these methods in addition to those from :class:`BufferedIOBase` and :class:`IOBase`: @@ -548,7 +548,7 @@ Buffered Streams raw stream blocks. -.. class:: BufferedRWPair(reader, writer[, buffer_size[, max_buffer_size]]) +.. class:: BufferedRWPair(reader, writer, buffer_size, max_buffer_size=DEFAULT_BUFFER_SIZE) A combined buffered writer and reader object for a raw stream that can be written to and read from. It has and supports both :meth:`read`, :meth:`write`, @@ -559,14 +559,15 @@ Buffered Streams writeable respectively. If the *buffer_size* is omitted it defaults to :data:`DEFAULT_BUFFER_SIZE`. - *max_buffer_size* is unused and deprecated. + A fourth argument, *max_buffer_size*, is supported, but unused and + deprecated. :class:`BufferedRWPair` implements all of :class:`BufferedIOBase`\'s methods except for :meth:`~BufferedIOBase.detach`, which raises :exc:`UnsupportedOperation`. -.. class:: BufferedRandom(raw[, buffer_size[, max_buffer_size]]) +.. class:: BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE) A buffered interface to random access streams. It inherits :class:`BufferedReader` and :class:`BufferedWriter`. @@ -575,7 +576,7 @@ Buffered Streams in the first argument. If the *buffer_size* is omitted it defaults to :data:`DEFAULT_BUFFER_SIZE`. - *max_buffer_size* is unused and deprecated. + A third argument, *max_buffer_size*, is supported, but unused and deprecated. :class:`BufferedRandom` is capable of anything :class:`BufferedReader` or :class:`BufferedWriter` can do. @@ -633,7 +634,7 @@ Text I/O written. -.. class:: TextIOWrapper(buffer[, encoding[, errors[, newline[, line_buffering]]]]) +.. class:: TextIOWrapper(buffer, encoding=None, errors=None, newline=None, line_buffering=False) A buffered text stream over a :class:`BufferedIOBase` raw stream, *buffer*. It inherits :class:`TextIOBase`. @@ -676,7 +677,7 @@ Text I/O Whether line buffering is enabled. -.. class:: StringIO([initial_value[, newline]]) +.. class:: StringIO(initial_value='', newline=None) An in-memory stream for text. It inherits :class:`TextIOWrapper`. |