Confused about Python's with statement
<p>I saw some code in the Whoosh documentation:</p>

<pre><code>with ix.searcher() as searcher:
    query = QueryParser("content", ix.schema).parse(u"ship")
    results = searcher.search(query)
</code></pre>

<p>I read that the with statement executes __ enter__ and __ exit__ methods and they are really useful in the forms "with file_pointer:" or "with lock:". But no literature is ever enlightening. And the various examples shows inconsistency when <strong>translating between the "with" form and the conventional form</strong> (yes its subjective).</p>

<p>Please explain </p>

<ul>
<li>what is the with statement</li>
<li>and the "as" statement here</li>
<li>and best practices to translate between both forms</li>
<li>what kinds of classes lend them to with blocks</li>
</ul>

<hr>

<p><strong>Epilogue</strong></p>

<p>The article on <a href="http://effbot.org/zone/python-with-statement.htm" rel="nofollow">http://effbot.org/zone/python-with-statement.htm</a> has the best explanation. It all became clear when I scrolled to the bottom of the page and saw a familiar file operation done in with. <a href="http://stackoverflow.com/users/190597/unutbu">http://stackoverflow.com/users/190597/unutbu</a> ,wish you had answered instead of commented. </p>
