summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-07-27 18:37:33 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-07-27 18:37:33 (GMT)
commit9dd8dc3fee7970cbc40b4686957aa3eaf15f91f0 (patch)
treecbf6c875d3e8943ea5aaa5b67e5bc4046a7cf0d7 /Doc
parent75a832d4e776ae6ee4aca1443cd595420b551b47 (diff)
downloadcpython-9dd8dc3fee7970cbc40b4686957aa3eaf15f91f0.zip
cpython-9dd8dc3fee7970cbc40b4686957aa3eaf15f91f0.tar.gz
cpython-9dd8dc3fee7970cbc40b4686957aa3eaf15f91f0.tar.bz2
Add example
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libstringio.tex37
1 files changed, 37 insertions, 0 deletions
diff --git a/Doc/lib/libstringio.tex b/Doc/lib/libstringio.tex
index 3992e43..2431251 100644
--- a/Doc/lib/libstringio.tex
+++ b/Doc/lib/libstringio.tex
@@ -37,6 +37,24 @@ such mixing can cause this method to raise \exception{UnicodeError}.
Free the memory buffer.
\end{methoddesc}
+Example usage:
+
+\begin{verbatim}
+import StringIO
+
+output = StringIO.StringIO()
+output.write('First line.\n')
+print >>output, 'Second line.'
+
+# Retrieve file contents -- this will be
+# 'First line.\nSecond line.\n'
+contents = output.getvalue()
+
+# Close object and discard memory buffer --
+# .getvalue() will now raise an exception.
+output.close()
+\end{verbatim}
+
\section{\module{cStringIO} ---
Faster version of \module{StringIO}}
@@ -82,3 +100,22 @@ The following data objects are provided as well:
There is a C API to the module as well; refer to the module source for
more information.
+
+Example usage:
+
+\begin{verbatim}
+import cStringIO
+
+output = cStringIO.StringIO()
+output.write('First line.\n')
+print >>output, 'Second line.'
+
+# Retrieve file contents -- this will be
+# 'First line.\nSecond line.\n'
+contents = output.getvalue()
+
+# Close object and discard memory buffer --
+# .getvalue() will now raise an exception.
+output.close()
+\end{verbatim}
+