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 on 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.
19 The following methods of
\class{StringIO
} objects require special
22 \begin{methoddesc
}{getvalue
}{}
23 Retrieve the entire contents of the ``file'' at any time before the
24 \class{StringIO
} object's
\method{close()
} method is called.
27 \begin{methoddesc
}{close
}{}
28 Free the memory buffer.
32 \section{\module{cStringIO
} ---
33 Faster version of
\module{StringIO
}}
35 \declaremodule{builtin
}{cStringIO
}
36 \modulesynopsis{Faster version of
\module{StringIO
}, but not
38 \moduleauthor{Jim Fulton
}{jfulton@digicool.com
}
39 \sectionauthor{Fred L. Drake, Jr.
}{fdrake@acm.org
}
41 The module
\module{cStringIO
} provides an interface similar to that of
42 the
\refmodule{StringIO
} module. Heavy use of
\class{StringIO.StringIO
}
43 objects can be made more efficient by using the function
44 \function{StringIO()
} from this module instead.
46 Since this module provides a factory function which returns objects of
47 built-in types, there's no way to build your own version using
48 subclassing. Use the original
\refmodule{StringIO
} module in that case.
50 The following data objects are provided as well:
53 \begin{datadesc
}{InputType
}
54 The type object of the objects created by calling
55 \function{StringIO
} with a string parameter.
58 \begin{datadesc
}{OutputType
}
59 The type object of the objects returned by calling
60 \function{StringIO
} with no parameters.
64 There is a C API to the module as well; refer to the module source for