blob: c48c28ec4345567523c5a5b8ee90e6ac185d3f8f [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 Drakecd71aa21999-02-18 21:13:03 +000034
Fred Drakeb91e9341998-07-23 17:59:49 +000035\declaremodule{builtin}{cStringIO}
Fred Drakeb91e9341998-07-23 17:59:49 +000036\modulesynopsis{Faster version of \module{StringIO}, but not subclassable.}
Fred Drakecd71aa21999-02-18 21:13:03 +000037\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
Fred Drake9463de21998-04-11 20:05:43 +000038
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.