Popular recipes by srid http://code.activestate.com/recipes/users/4053089/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> Pickle data abstraction using `with' statement (Python) 2007-05-02T04:18:33-07:00sridhttp://code.activestate.com/recipes/users/4053089/http://code.activestate.com/recipes/511510-pickle-data-abstraction-using-with-statement/ <p style="color: grey"> Python recipe 511510 by <a href="/recipes/users/4053089/">srid</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>The <code>pickle' module provides a convenient way to serialize Python data structures to disk. With the introduction of</code>with' statement in Python 2.5, we can write code that reads/updates Python data in a more intuitive way.</p>