Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{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 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 6 | This module implements a file-like class, \class{StringIO}, |
Fred Drake | af8a015 | 1998-01-14 14:51:31 +0000 | [diff] [blame] | 7 | that reads and writes a string buffer (also known as \emph{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 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 10 | \begin{classdesc}{StringIO}{\optional{buffer}} |
| 11 | When a \class{StringIO} object is created, it can be initialized |
Guido van Rossum | cda3d7d | 1997-03-03 16:01:21 +0000 | [diff] [blame] | 12 | to an existing string by passing the string to the constructor. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 13 | If no string is given, the \class{StringIO} will start empty. |
| 14 | \end{classdesc} |
Guido van Rossum | cda3d7d | 1997-03-03 16:01:21 +0000 | [diff] [blame] | 15 | |
Fred Drake | 7e9383a | 1998-04-11 18:05:24 +0000 | [diff] [blame] | 16 | The following methods of \class{StringIO} objects require special |
| 17 | mention: |
| 18 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 19 | \begin{methoddesc}{getvalue}{} |
| 20 | Retrieve the entire contents of the ``file'' at any time before the |
| 21 | \class{StringIO} object's \method{close()} method is called. |
| 22 | \end{methoddesc} |
| 23 | |
| 24 | \begin{methoddesc}{close}{} |
| 25 | Free the memory buffer. |
| 26 | \end{methoddesc} |
Fred Drake | 9463de2 | 1998-04-11 20:05:43 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | \section{Built-in Module \module{cStringIO}} |
| 30 | \bimodindex{cStringIO} |
| 31 | \label{module-cStringIO} |
| 32 | |
| 33 | % This section was written by Fred L. Drake, Jr. <fdrake@acm.org> |
| 34 | |
| 35 | The module \module{cStringIO} provides an interface similar to that of |
| 36 | the \module{StringIO} module. Heavy use of \class{StringIO.StringIO} |
| 37 | objects can be made more efficient by using the function |
| 38 | \function{StringIO()} from this module instead. |
| 39 | |
| 40 | Since this module provides a factory function which returns objects of |
| 41 | built-in types, there's no way to build your own version using |
| 42 | subclassing. Use the original \module{StringIO} module in that case. |