[Python-checkins] r50866 - python/trunk/Doc/lib/libstringio.tex

andrew.kuchling python-checkins at python.org
Thu Jul 27 20:37:33 CEST 2006


Author: andrew.kuchling
Date: Thu Jul 27 20:37:33 2006
New Revision: 50866

Modified:
   python/trunk/Doc/lib/libstringio.tex
Log:
Add example

Modified: python/trunk/Doc/lib/libstringio.tex
==============================================================================
--- python/trunk/Doc/lib/libstringio.tex	(original)
+++ python/trunk/Doc/lib/libstringio.tex	Thu Jul 27 20:37:33 2006
@@ -37,6 +37,24 @@
 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 @@
 
 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}
+


More information about the Python-checkins mailing list