Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Doc / lib / libstringio.tex
blobc268690ea0d56141cfeec5cedf7e0ee8cf17a13b
1 \section{\module{StringIO} ---
2 Read and write strings as files}
4 \declaremodule{standard}{StringIO}
5 \modulesynopsis{Read and write strings as if they were files.}
8 This module implements a file-like class, \class{StringIO},
9 that reads and writes a string buffer (also known as \emph{memory
10 files}). See the description of file objects for operations (section
11 \ref{bltin-file-objects}).
13 \begin{classdesc}{StringIO}{\optional{buffer}}
14 When a \class{StringIO} object is created, it can be initialized
15 to an existing string by passing the string to the constructor.
16 If no string is given, the \class{StringIO} will start empty.
18 The \class{StringIO} object can accept either Unicode or 8-bit
19 strings, but mixing the two may take some care. If both are used,
20 8-bit strings that cannot be interpreted as 7-bit \ASCII{} (that
21 use the 8th bit) will cause a \exception{UnicodeError} to be raised
22 when \method{getvalue()} is called.
23 \end{classdesc}
25 The following methods of \class{StringIO} objects require special
26 mention:
28 \begin{methoddesc}{getvalue}{}
29 Retrieve the entire contents of the ``file'' at any time before the
30 \class{StringIO} object's \method{close()} method is called. See the
31 note above for information about mixing Unicode and 8-bit strings;
32 such mixing can cause this method to raise \exception{UnicodeError}.
33 \end{methoddesc}
35 \begin{methoddesc}{close}{}
36 Free the memory buffer.
37 \end{methoddesc}
40 \section{\module{cStringIO} ---
41 Faster version of \module{StringIO}}
43 \declaremodule{builtin}{cStringIO}
44 \modulesynopsis{Faster version of \module{StringIO}, but not
45 subclassable.}
46 \moduleauthor{Jim Fulton}{jfulton@digicool.com}
47 \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
49 The module \module{cStringIO} provides an interface similar to that of
50 the \refmodule{StringIO} module. Heavy use of \class{StringIO.StringIO}
51 objects can be made more efficient by using the function
52 \function{StringIO()} from this module instead.
54 Since this module provides a factory function which returns objects of
55 built-in types, there's no way to build your own version using
56 subclassing. Use the original \refmodule{StringIO} module in that case.
58 Unlike the memory files implemented by the \refmodule{StringIO}
59 module, those provided by this module are not able to accept Unicode
60 strings that cannot be encoded as plain \ASCII{} strings.
62 Another difference from the \refmodule{StringIO} module is that calling
63 \function{StringIO()} with a string parameter creates a read-only object.
64 Unlike an object created without a string parameter, it does not have
65 write methods.
67 The following data objects are provided as well:
70 \begin{datadesc}{InputType}
71 The type object of the objects created by calling
72 \function{StringIO} with a string parameter.
73 \end{datadesc}
75 \begin{datadesc}{OutputType}
76 The type object of the objects returned by calling
77 \function{StringIO} with no parameters.
78 \end{datadesc}
81 There is a C API to the module as well; refer to the module source for
82 more information.