| |
- __builtin__.object
-
- __builtin__.type
- IOBase
-
- BufferedIOBase
-
- BufferedRWPair
- BytesIO
- RawIOBase
- TextIOBase
-
- TextIOWrapper
-
- StringIO
- _io._RawIOBase(_io._IOBase)
-
- _io.FileIO
- _BufferedIOMixin(BufferedIOBase)
-
- BufferedReader
- BufferedWriter
-
- BufferedRandom(BufferedWriter, BufferedReader)
- exceptions.IOError(exceptions.EnvironmentError)
-
- BlockingIOError
- UnsupportedOperation(exceptions.ValueError, exceptions.IOError)
- exceptions.ValueError(exceptions.StandardError)
-
- UnsupportedOperation(exceptions.ValueError, exceptions.IOError)
class BufferedIOBase(IOBase) |
|
Base class for buffered IO objects.
The main difference with RawIOBase is that the read() method
supports omitting the size argument, and does not have a default
implementation that defers to readinto().
In addition, read(), readinto() and write() may raise
BlockingIOError if the underlying raw stream is in non-blocking
mode and not ready; unlike their raw counterparts, they will never
return None.
A typical implementation should not inherit from a RawIOBase
implementation, but wrap one. |
|
- Method resolution order:
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- detach(self)
- Separate the underlying raw stream from the buffer and return it.
After the raw stream has been detached, the buffer is in an unusable
state.
- read(self, n=None)
- Read and return up to n bytes.
If the argument is omitted, None, or negative, reads and
returns all data until EOF.
If the argument is positive, and the underlying raw stream is
not 'interactive', multiple raw reads may be issued to satisfy
the byte count (unless EOF is reached first). But for
interactive raw streams (XXX and for pipes?), at most one raw
read will be issued, and a short result does not imply that
EOF is imminent.
Returns an empty bytes array on EOF.
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
- read1(self, n=None)
- Read up to n bytes with at most one read() system call.
- readinto(self, b)
- Read up to len(b) bytes into b.
Like read(), this may issue multiple reads to the underlying raw
stream, unless the latter is 'interactive'.
Returns the number of bytes read (0 for EOF).
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
- write(self, b)
- Write the given buffer to the IO stream.
Return the number of bytes written, which is never less than
len(b).
Raises BlockingIOError if the buffer is full and the
underlying raw stream cannot accept more data at the moment.
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- close(self)
- Flush and close the IO object.
This method has no effect if the file is already closed.
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- flush(self)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- isatty(self)
- Return whether this is an 'interactive' stream.
Return False if it can't be determined.
- next(self)
- readable(self)
- Return whether object was opened for reading.
If False, read() will raise IOError.
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- seek(self, pos, whence=0)
- Change stream position.
Change the stream position to byte offset pos. Argument pos is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
- seekable(self)
- Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().
- tell(self)
- Return current stream position.
- truncate(self, pos=None)
- Truncate file to size bytes.
Size defaults to the current IO position as reported by tell(). Return
the new size.
- writable(self)
- Return whether object was opened for writing.
If False, write() and truncate() will raise IOError.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- closed
- closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BufferedRWPair(BufferedIOBase) |
|
A buffered reader and writer object together.
A buffered reader object and buffered writer object put together to
form a sequential IO object that can read and write. This is typically
used with a socket or two-way pipe.
reader and writer are RawIOBase objects that are readable and
writeable respectively. If the buffer_size is omitted it defaults to
DEFAULT_BUFFER_SIZE. |
|
- Method resolution order:
- BufferedRWPair
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, reader, writer, buffer_size=8192, max_buffer_size=None)
- Constructor.
The arguments are two RawIO instances.
- close(self)
- flush(self)
- isatty(self)
- peek(self, n=0)
- read(self, n=None)
- read1(self, n)
- readable(self)
- readinto(self, b)
- writable(self)
- write(self, b)
Data descriptors defined here:
- closed
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from BufferedIOBase:
- detach(self)
- Separate the underlying raw stream from the buffer and return it.
After the raw stream has been detached, the buffer is in an unusable
state.
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- next(self)
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- seek(self, pos, whence=0)
- Change stream position.
Change the stream position to byte offset pos. Argument pos is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
- seekable(self)
- Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().
- tell(self)
- Return current stream position.
- truncate(self, pos=None)
- Truncate file to size bytes.
Size defaults to the current IO position as reported by tell(). Return
the new size.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BufferedRandom(BufferedWriter, BufferedReader) |
|
A buffered interface to random access streams.
The constructor creates a reader and writer for a seekable stream,
raw, given in the first argument. If the buffer_size is omitted it
defaults to DEFAULT_BUFFER_SIZE. |
|
- Method resolution order:
- BufferedRandom
- BufferedWriter
- BufferedReader
- _BufferedIOMixin
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, raw, buffer_size=8192, max_buffer_size=None)
- peek(self, n=0)
- read(self, n=None)
- read1(self, n)
- readinto(self, b)
- seek(self, pos, whence=0)
- tell(self)
- truncate(self, pos=None)
- write(self, b)
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from BufferedWriter:
- flush(self)
Methods inherited from _BufferedIOMixin:
- __repr__(self)
- close(self)
- detach(self)
- fileno(self)
- isatty(self)
- readable(self)
- seekable(self)
- writable(self)
Data descriptors inherited from _BufferedIOMixin:
- closed
- mode
- name
- raw
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- next(self)
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BufferedReader(_BufferedIOMixin) |
|
BufferedReader(raw[, buffer_size])
A buffer for a readable, sequential BaseRawIO object.
The constructor creates a BufferedReader for the given readable raw
stream and buffer_size. If buffer_size is omitted, DEFAULT_BUFFER_SIZE
is used. |
|
- Method resolution order:
- BufferedReader
- _BufferedIOMixin
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, raw, buffer_size=8192)
- Create a new buffered reader using the given readable raw IO object.
- peek(self, n=0)
- Returns buffered bytes without advancing the position.
The argument indicates a desired minimal number of bytes; we
do at most one raw read to satisfy it. We never return more
than self.buffer_size.
- read(self, n=None)
- Read n bytes.
Returns exactly n bytes of data unless the underlying raw IO
stream reaches EOF or if the call would block in non-blocking
mode. If n is negative, read until EOF or until read() would
block.
- read1(self, n)
- Reads up to n bytes, with at most one read() system call.
- seek(self, pos, whence=0)
- tell(self)
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from _BufferedIOMixin:
- __repr__(self)
- close(self)
- detach(self)
- fileno(self)
- flush(self)
- isatty(self)
- readable(self)
- seekable(self)
- truncate(self, pos=None)
- writable(self)
Data descriptors inherited from _BufferedIOMixin:
- closed
- mode
- name
- raw
Methods inherited from BufferedIOBase:
- readinto(self, b)
- Read up to len(b) bytes into b.
Like read(), this may issue multiple reads to the underlying raw
stream, unless the latter is 'interactive'.
Returns the number of bytes read (0 for EOF).
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
- write(self, b)
- Write the given buffer to the IO stream.
Return the number of bytes written, which is never less than
len(b).
Raises BlockingIOError if the buffer is full and the
underlying raw stream cannot accept more data at the moment.
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- next(self)
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BufferedWriter(_BufferedIOMixin) |
|
A buffer for a writeable sequential RawIO object.
The constructor creates a BufferedWriter for the given writeable raw
stream. If the buffer_size is not given, it defaults to
DEFAULT_BUFFER_SIZE. |
|
- Method resolution order:
- BufferedWriter
- _BufferedIOMixin
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, raw, buffer_size=8192, max_buffer_size=None)
- flush(self)
- seek(self, pos, whence=0)
- tell(self)
- truncate(self, pos=None)
- write(self, b)
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from _BufferedIOMixin:
- __repr__(self)
- close(self)
- detach(self)
- fileno(self)
- isatty(self)
- readable(self)
- seekable(self)
- writable(self)
Data descriptors inherited from _BufferedIOMixin:
- closed
- mode
- name
- raw
Methods inherited from BufferedIOBase:
- read(self, n=None)
- Read and return up to n bytes.
If the argument is omitted, None, or negative, reads and
returns all data until EOF.
If the argument is positive, and the underlying raw stream is
not 'interactive', multiple raw reads may be issued to satisfy
the byte count (unless EOF is reached first). But for
interactive raw streams (XXX and for pipes?), at most one raw
read will be issued, and a short result does not imply that
EOF is imminent.
Returns an empty bytes array on EOF.
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
- read1(self, n=None)
- Read up to n bytes with at most one read() system call.
- readinto(self, b)
- Read up to len(b) bytes into b.
Like read(), this may issue multiple reads to the underlying raw
stream, unless the latter is 'interactive'.
Returns the number of bytes read (0 for EOF).
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- next(self)
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BytesIO(BufferedIOBase) |
|
Buffered I/O implementation using an in-memory bytes buffer. |
|
- Method resolution order:
- BytesIO
- BufferedIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __getstate__(self)
- __init__(self, initial_bytes=None)
- getvalue(self)
- Return the bytes value (contents) of the buffer
- read(self, n=None)
- read1(self, n)
- This is the same as read.
- readable(self)
- seek(self, pos, whence=0)
- seekable(self)
- tell(self)
- truncate(self, pos=None)
- writable(self)
- write(self, b)
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from BufferedIOBase:
- detach(self)
- Separate the underlying raw stream from the buffer and return it.
After the raw stream has been detached, the buffer is in an unusable
state.
- readinto(self, b)
- Read up to len(b) bytes into b.
Like read(), this may issue multiple reads to the underlying raw
stream, unless the latter is 'interactive'.
Returns the number of bytes read (0 for EOF).
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- close(self)
- Flush and close the IO object.
This method has no effect if the file is already closed.
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- flush(self)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- isatty(self)
- Return whether this is an 'interactive' stream.
Return False if it can't be determined.
- next(self)
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- closed
- closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class FileIO(_RawIOBase) |
|
file(name: str[, mode: str]) -> file IO object
Open a file. The mode can be 'r' (default), 'w' or 'a' for reading,
writing or appending. The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing. Add a '+' to the mode to allow simultaneous
reading and writing. |
|
- Method resolution order:
- FileIO
- _RawIOBase
- _IOBase
- __builtin__.object
Methods defined here:
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __init__(...)
- x.__init__(...) initializes x; see help(type(x)) for signature
- __repr__(...)
- x.__repr__() <==> repr(x)
- close(...)
- close() -> None. Close the file.
A closed file cannot be used for further I/O operations. close() may be
called more than once without error.
- fileno(...)
- fileno() -> int. Return the underlying file descriptor (an integer).
- isatty(...)
- isatty() -> bool. True if the file is connected to a TTY device.
- read(...)
- read(size: int) -> bytes. read at most size bytes, returned as bytes.
Only makes one system call, so less data may be returned than requested
In non-blocking mode, returns None if no data is available.
On end-of-file, returns ''.
- readable(...)
- readable() -> bool. True if file was opened in a read mode.
- readall(...)
- readall() -> bytes. read all data from the file, returned as bytes.
In non-blocking mode, returns as much as is immediately available,
or None if no data is available. On end-of-file, returns ''.
- readinto(...)
- readinto() -> Same as RawIOBase.readinto().
- seek(...)
- seek(offset: int[, whence: int]) -> int. Move to new file position
and return the file position.
Argument offset is a byte count. Optional argument whence defaults to
SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values
are SEEK_CUR or 1 (move relative to current position, positive or negative),
and SEEK_END or 2 (move relative to end of file, usually negative, although
many platforms allow seeking beyond the end of a file).
Note that not all file objects are seekable.
- seekable(...)
- seekable() -> bool. True if file supports random-access.
- tell(...)
- tell() -> int. Current file position.
Can raise OSError for non seekable files.
- truncate(...)
- truncate([size: int]) -> int. Truncate the file to at most size bytes and
return the truncated size.
Size defaults to the current file position, as returned by tell().
The current file position is changed to the value of size.
- writable(...)
- writable() -> bool. True if file was opened in a write mode.
- write(...)
- write(b: bytes) -> int. Write bytes b to file, return number written.
Only makes one system call, so not all of the data may be written.
The number of bytes actually written is returned. In non-blocking mode,
returns None if the write would block.
Data descriptors defined here:
- closed
- True if the file is closed
- closefd
- True if the file descriptor will be closed by close().
- mode
- String giving the file mode
Data and other attributes defined here:
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
Methods inherited from _IOBase:
- __enter__(...)
- __exit__(...)
- __iter__(...)
- x.__iter__() <==> iter(x)
- flush(...)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- next(...)
- x.next() -> the next value, or raise StopIteration
- readline(...)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(...)
- 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.
- writelines(...)
|
class IOBase(__builtin__.object) |
| |
Methods defined here:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- close(self)
- Flush and close the IO object.
This method has no effect if the file is already closed.
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- flush(self)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- isatty(self)
- Return whether this is an 'interactive' stream.
Return False if it can't be determined.
- next(self)
- readable(self)
- Return whether object was opened for reading.
If False, read() will raise IOError.
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- seek(self, pos, whence=0)
- Change stream position.
Change the stream position to byte offset pos. Argument pos is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
- seekable(self)
- Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().
- tell(self)
- Return current stream position.
- truncate(self, pos=None)
- Truncate file to size bytes.
Size defaults to the current IO position as reported by tell(). Return
the new size.
- writable(self)
- Return whether object was opened for writing.
If False, write() and truncate() will raise IOError.
- writelines(self, lines)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- closed
- closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class RawIOBase(IOBase) |
|
Base class for raw binary I/O. |
|
- Method resolution order:
- RawIOBase
- IOBase
- __builtin__.object
Methods defined here:
- read(self, n=-1)
- Read and return up to n bytes.
Returns an empty bytes object on EOF, or None if the object is
set not to block and has no data to read.
- readall(self)
- Read until EOF, using multiple read() call.
- readinto(self, b)
- Read up to len(b) bytes into b.
Returns number of bytes read (0 for EOF), or None if the object
is set not to block and has no data to read.
- write(self, b)
- Write the given buffer to the IO stream.
Returns the number of bytes written, which may be less than len(b).
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- close(self)
- Flush and close the IO object.
This method has no effect if the file is already closed.
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- flush(self)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- isatty(self)
- Return whether this is an 'interactive' stream.
Return False if it can't be determined.
- next(self)
- readable(self)
- Return whether object was opened for reading.
If False, read() will raise IOError.
- readline(self, limit=-1)
- Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
- readlines(self, hint=None)
- 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.
- seek(self, pos, whence=0)
- Change stream position.
Change the stream position to byte offset pos. Argument pos is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
- seekable(self)
- Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().
- tell(self)
- Return current stream position.
- truncate(self, pos=None)
- Truncate file to size bytes.
Size defaults to the current IO position as reported by tell(). Return
the new size.
- writable(self)
- Return whether object was opened for writing.
If False, write() and truncate() will raise IOError.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- closed
- closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class StringIO(TextIOWrapper) |
|
Text I/O implementation using an in-memory buffer.
The initial_value argument sets the value of object. The newline
argument is like the one of TextIOWrapper's constructor. |
|
- Method resolution order:
- StringIO
- TextIOWrapper
- TextIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, initial_value=u'', newline=u'\n')
- __repr__(self)
- detach(self)
- getvalue(self)
Data descriptors defined here:
- encoding
- errors
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from TextIOWrapper:
- close(self)
- fileno(self)
- flush(self)
- isatty(self)
- next(self)
- read(self, n=None)
- readable(self)
- readline(self, limit=None)
- seek(self, cookie, whence=0)
- seekable(self)
- tell(self)
- truncate(self, pos=None)
- writable(self)
- write(self, s)
Data descriptors inherited from TextIOWrapper:
- buffer
- closed
- line_buffering
- name
- newlines
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class TextIOBase(IOBase) |
|
Base class for text I/O.
This class provides a character and line based interface to stream
I/O. There is no readinto method because Python's character strings
are immutable. There is no public constructor. |
|
- Method resolution order:
- TextIOBase
- IOBase
- __builtin__.object
Methods defined here:
- detach(self)
- Separate the underlying buffer from the TextIOBase and return it.
After the underlying buffer has been detached, the TextIO is in an
unusable state.
- read(self, n=-1)
- Read at most n characters from stream.
Read from underlying buffer until we have n characters or we hit EOF.
If n is negative or omitted, read until EOF.
- readline(self)
- Read until newline or EOF.
Returns an empty string if EOF is hit immediately.
- truncate(self, pos=None)
- Truncate size to pos.
- write(self, s)
- Write string s to stream.
Data descriptors defined here:
- encoding
- Subclasses should override.
- errors
- Error setting of the decoder or encoder.
Subclasses should override.
- newlines
- Line endings translated so far.
Only line endings translated during reading are considered.
Subclasses should override.
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- close(self)
- Flush and close the IO object.
This method has no effect if the file is already closed.
- fileno(self)
- Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
- flush(self)
- Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- isatty(self)
- Return whether this is an 'interactive' stream.
Return False if it can't be determined.
- next(self)
- readable(self)
- Return whether object was opened for reading.
If False, read() will raise IOError.
- readlines(self, hint=None)
- 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.
- seek(self, pos, whence=0)
- Change stream position.
Change the stream position to byte offset pos. Argument pos is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
- seekable(self)
- Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().
- tell(self)
- Return current stream position.
- writable(self)
- Return whether object was opened for writing.
If False, write() and truncate() will raise IOError.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- closed
- closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class TextIOWrapper(TextIOBase) |
|
Character and line based layer over a BufferedIOBase object, buffer.
encoding gives the name of the encoding that the stream will be
decoded or encoded with. It defaults to locale.getpreferredencoding.
errors determines the strictness of encoding and decoding (see the
codecs.register) and defaults to "strict".
newline can be None, '', '\n', '\r', or '\r\n'. It controls the
handling of line endings. If it is None, universal newlines is
enabled. With this enabled, on input, the lines endings '\n', '\r',
or '\r\n' are translated to '\n' before being returned to the
caller. Conversely, on output, '\n' is translated to the system
default line separator, os.linesep. If newline is any other of its
legal values, that newline becomes the newline when the file is read
and it is returned untranslated. On output, '\n' is converted to the
newline.
If line_buffering is True, a call to flush is implied when a call to
write contains a newline character. |
|
- Method resolution order:
- TextIOWrapper
- TextIOBase
- IOBase
- __builtin__.object
Methods defined here:
- __init__(self, buffer, encoding=None, errors=None, newline=None, line_buffering=False)
- __repr__(self)
- close(self)
- detach(self)
- fileno(self)
- flush(self)
- isatty(self)
- next(self)
- read(self, n=None)
- readable(self)
- readline(self, limit=None)
- seek(self, cookie, whence=0)
- seekable(self)
- tell(self)
- truncate(self, pos=None)
- writable(self)
- write(self, s)
Data descriptors defined here:
- buffer
- closed
- encoding
- errors
- line_buffering
- name
- newlines
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from IOBase:
- __del__(self)
- Destructor. Calls close().
- __enter__(self)
- Context management protocol. Returns self.
- __exit__(self, *args)
- Context management protocol. Calls close()
- __iter__(self)
- readlines(self, hint=None)
- 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.
- writelines(self, lines)
Data descriptors inherited from IOBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from IOBase:
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
|