Guido van Rossum | cda3d7d | 1997-03-03 16:01:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \sectcode{StringIO}} |
Guido van Rossum | 5320998 | 1997-07-17 16:29:04 +0000 | [diff] [blame^] | 2 | \label{module-StringIO} |
Guido van Rossum | cda3d7d | 1997-03-03 16:01:21 +0000 | [diff] [blame] | 3 | |
| 4 | \stmodindex{StringIO} |
| 5 | |
| 6 | This module implements a file-like class, \code{StringIO}, |
Fred Drake | 387c575 | 1997-04-02 14:51:56 +0000 | [diff] [blame] | 7 | that reads and writes a string buffer (also known as {\em memory |
Guido van Rossum | cda3d7d | 1997-03-03 16:01:21 +0000 | [diff] [blame] | 8 | files}). See the description on file objects for operations. |
| 9 | |
| 10 | When a \code{StringIO} object is created, it can be initialized |
| 11 | to an existing string by passing the string to the constructor. |
| 12 | If no string is given, the \code{StringIO} will start empty. |
| 13 | |
Guido van Rossum | 5320998 | 1997-07-17 16:29:04 +0000 | [diff] [blame^] | 14 | The method \code{getvalue()} can be called to retrieve the entire |
| 15 | contents of the ``file'' at any time before the \code{StringIO} |
| 16 | object's \code{close()} method is called. Calling \code{close()} will |
| 17 | free the memory buffer. |