I saw the code in the Whoosh documentation:
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(u"ship")
results = searcher.search(query)
I read that the with statement executes the __ enter__ and __ exit__ methods, and they are really useful in forms with "file_pointer:" or "with lock:". But no literature ever enlightens. And various examples show inconsistency when the translation is between the form “c” and the ordinary form (yes, its subjective).
Explain, please
- what is the with statement
- and the like operator here
- and best practices for translating between both forms
- which classes provide them with blocks
Epilogue
http://effbot.org/zone/python-with-statement.htm . , . https://stackoverflow.com/users/190597/unutbu, , .