blob: 6b7d2c560551a15ef7760df3cae9fceff120bf76 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{StringIO}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{StringIO}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00003
Fred Drakeb91e9341998-07-23 17:59:49 +00004
5\modulesynopsis{Read and write strings as if they were files.}
6
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00007
Fred Drake8fe533e1998-03-27 05:27:08 +00008This module implements a file-like class, \class{StringIO},
Fred Drakeaf8a0151998-01-14 14:51:31 +00009that reads and writes a string buffer (also known as \emph{memory
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000010files}). See the description on file objects for operations.
11
Fred Drake8fe533e1998-03-27 05:27:08 +000012\begin{classdesc}{StringIO}{\optional{buffer}}
13When a \class{StringIO} object is created, it can be initialized
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000014to an existing string by passing the string to the constructor.
Fred Drake8fe533e1998-03-27 05:27:08 +000015If no string is given, the \class{StringIO} will start empty.
16\end{classdesc}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000017
Fred Drake7e9383a1998-04-11 18:05:24 +000018The following methods of \class{StringIO} objects require special
19mention:
20
Fred Drake8fe533e1998-03-27 05:27:08 +000021\begin{methoddesc}{getvalue}{}
22Retrieve 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}{}
27Free the memory buffer.
28\end{methoddesc}
Fred Drake9463de21998-04-11 20:05:43 +000029
30
31\section{Built-in Module \module{cStringIO}}
Fred Drakeb91e9341998-07-23 17:59:49 +000032\declaremodule{builtin}{cStringIO}
33
34\modulesynopsis{Faster version of \module{StringIO}, but not subclassable.}
35
Fred Drake9463de21998-04-11 20:05:43 +000036
37% This section was written by Fred L. Drake, Jr. <fdrake@acm.org>
38
39The module \module{cStringIO} provides an interface similar to that of
40the \module{StringIO} module. Heavy use of \class{StringIO.StringIO}
41objects can be made more efficient by using the function
42\function{StringIO()} from this module instead.
43
44Since this module provides a factory function which returns objects of
45built-in types, there's no way to build your own version using
46subclassing. Use the original \module{StringIO} module in that case.