Popular recipes tagged "stringio"http://code.activestate.com/recipes/tags/stringio/popular/2009-02-24T00:01:16-08:00ActiveState Code Recipes'with' statement for StringIO (Python) 2009-02-24T00:01:16-08:00sridhttp://code.activestate.com/recipes/users/4053089/http://code.activestate.com/recipes/576650-with-statement-for-stringio/ <p style="color: grey"> Python recipe 576650 by <a href="/recipes/users/4053089/">srid</a> (<a href="/recipes/tags/stringio/">stringio</a>, <a href="/recipes/tags/with_statement/">with_statement</a>). Revision 3. </p> <p>NOTE: Consider this recipe obsolete. Instead use <code>contextlib.closing</code> (see comment below).</p> <p>This contextmanager adds 'with' statement support for StringIO. Peruse the following simple example:</p> <pre class="prettyprint"><code>with StringIO() as sio: function_accepting_file_handle(sio) print sio.getvalue() </code></pre>