blob: 86ebf46688ac77fb87da75430356bc07905628be [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{StringIO}}
Guido van Rossum53209981997-07-17 16:29:04 +00002\label{module-StringIO}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00003
4\stmodindex{StringIO}
5
Fred Drake8fe533e1998-03-27 05:27:08 +00006This module implements a file-like class, \class{StringIO},
Fred Drakeaf8a0151998-01-14 14:51:31 +00007that reads and writes a string buffer (also known as \emph{memory
Guido van Rossumcda3d7d1997-03-03 16:01:21 +00008files}). See the description on file objects for operations.
9
Fred Drake8fe533e1998-03-27 05:27:08 +000010\begin{classdesc}{StringIO}{\optional{buffer}}
11When a \class{StringIO} object is created, it can be initialized
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000012to an existing string by passing the string to the constructor.
Fred Drake8fe533e1998-03-27 05:27:08 +000013If no string is given, the \class{StringIO} will start empty.
14\end{classdesc}
Guido van Rossumcda3d7d1997-03-03 16:01:21 +000015
Fred Drake7e9383a1998-04-11 18:05:24 +000016The following methods of \class{StringIO} objects require special
17mention:
18
Fred Drake8fe533e1998-03-27 05:27:08 +000019\begin{methoddesc}{getvalue}{}
20Retrieve 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}{}
25Free the memory buffer.
26\end{methoddesc}
Fred Drake9463de21998-04-11 20:05:43 +000027
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
35The module \module{cStringIO} provides an interface similar to that of
36the \module{StringIO} module. Heavy use of \class{StringIO.StringIO}
37objects can be made more efficient by using the function
38\function{StringIO()} from this module instead.
39
40Since this module provides a factory function which returns objects of
41built-in types, there's no way to build your own version using
42subclassing. Use the original \module{StringIO} module in that case.