blob: 0e59e03d6989c2acdfa8b24a5858905990092af1 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{StringIO} ---
2 Read and write strings as if they were files.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{standard}{StringIO}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00004
Fred Drakeb91e9341998-07-23 17:59:49 +00005
6\modulesynopsis{Read and write strings as if they were files.}
7
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00008
Fred Drake8fe533e1998-03-27 05:27:08 +00009This module implements a file-like class, \class{StringIO},
Fred Drakeaf8a0151998-01-14 14:51:31 +000010that reads and writes a string buffer (also known as \emph{memory
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000011files}). See the description on file objects for operations.
12
Fred Drake8fe533e1998-03-27 05:27:08 +000013\begin{classdesc}{StringIO}{\optional{buffer}}
14When a \class{StringIO} object is created, it can be initialized
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000015to an existing string by passing the string to the constructor.
Fred Drake8fe533e1998-03-27 05:27:08 +000016If no string is given, the \class{StringIO} will start empty.
17\end{classdesc}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000018
Fred Drake7e9383a1998-04-11 18:05:24 +000019The following methods of \class{StringIO} objects require special
20mention:
21
Fred Drake8fe533e1998-03-27 05:27:08 +000022\begin{methoddesc}{getvalue}{}
23Retrieve the entire contents of the ``file'' at any time before the
24\class{StringIO} object's \method{close()} method is called.
25\end{methoddesc}
26
27\begin{methoddesc}{close}{}
28Free the memory buffer.
29\end{methoddesc}
Fred Drake9463de21998-04-11 20:05:43 +000030
31
Fred Drake295da241998-08-10 19:42:37 +000032\section{\module{cStringIO} ---
33 Faster version of \module{StringIO}, but not subclassable.}
Fred Drakeb91e9341998-07-23 17:59:49 +000034\declaremodule{builtin}{cStringIO}
35
36\modulesynopsis{Faster version of \module{StringIO}, but not subclassable.}
37
Fred Drake9463de21998-04-11 20:05:43 +000038
39% This section was written by Fred L. Drake, Jr. <fdrake@acm.org>
40
41The module \module{cStringIO} provides an interface similar to that of
42the \module{StringIO} module. Heavy use of \class{StringIO.StringIO}
43objects can be made more efficient by using the function
44\function{StringIO()} from this module instead.
45
46Since this module provides a factory function which returns objects of
47built-in types, there's no way to build your own version using
48subclassing. Use the original \module{StringIO} module in that case.