StringIO.StringIO
¶
-
class
StringIO.
StringIO
(buf='')[source]¶ class StringIO([buffer])
When a StringIO object is created, it can be initialized to an existing string by passing the string to the constructor. If no string is given, the StringIO will start empty.
The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause a UnicodeError to be raised when getvalue() is called.
Methods¶
__init__ ([buf]) |
|
__iter__ () |
|
close () |
Free the memory buffer. |
flush () |
Flush the internal buffer |
getvalue () |
Retrieve the entire contents of the “file” at any time before the StringIO object’s close() method is called. |
isatty () |
Returns False because StringIO objects are not connected to a tty-like device. |
next () |
A file object is its own iterator, for example iter(f) returns f (unless f is closed). |
read ([n]) |
Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes). |
readline ([length]) |
Read one entire line from the file. |
readlines ([sizehint]) |
Read until EOF using readline() and return a list containing the lines thus read. |
seek (pos[, mode]) |
Set the file’s current position. |
tell () |
Return the file’s current position. |
truncate ([size]) |
Truncate the file’s size. |
write (s) |
Write a string to the file. |
writelines (iterable) |
Write a sequence of strings to the file. |