class io.TextIOBase
Base class for text streams. 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. It inherits IOBase. There is no public constructor.
TextIOBase provides or overrides these data attributes and methods in addition to those from IOBase:
-
encoding -
The name of the encoding used to decode the stream’s bytes into strings, and to encode strings into bytes.
-
errors -
The error setting of the decoder or encoder.
-
newlines -
A string, a tuple of strings, or
None, indicating the newlines translated so far. Depending on the implementation and the initial constructor flags, this may not be available.
-
buffer -
The underlying binary buffer (a
BufferedIOBaseinstance) thatTextIOBasedeals with. This is not part of theTextIOBaseAPI and may not exist in some implementations.
-
detach() -
Separate the underlying binary buffer from the
TextIOBaseand return it.After the underlying buffer has been detached, the
TextIOBaseis in an unusable state.Some
TextIOBaseimplementations, likeStringIO, may not have the concept of an underlying buffer and calling this method will raiseUnsupportedOperation.New in version 3.1.
-
read(size) -
Read and return at most size characters from the stream as a single
str. If size is negative orNone, reads until EOF.
-
readline(size=-1) -
Read until newline or EOF and return a single
str. If the stream is already at EOF, an empty string is returned.If size is specified, at most size characters will be read.
-
seek(offset[, whence]) -
Change the stream position to the given offset. Behaviour depends on the whence parameter. The default value for whence is
SEEK_SET.-
SEEK_SETor0: seek from the start of the stream (the default); offset must either be a number returned byTextIOBase.tell(), or zero. Any other offset value produces undefined behaviour. -
SEEK_CURor1: “seek” to the current position; offset must be zero, which is a no-operation (all other values are unsupported). -
SEEK_ENDor2: seek to the end of the stream; offset must be zero (all other values are unsupported).
Return the new absolute position as an opaque number.
New in version 3.1: The
SEEK_*constants. -
-
tell() -
Return the current stream position as an opaque number. The number does not usually represent a number of bytes in the underlying binary storage.
-
write(s) -
Write the string s to the stream and return the number of characters written.
Please login to continue.