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