[Python-Dev] 'With' context documentation draft (was Re: Terminology for PEP 343 (original) (raw)

M.-A. Lemburg mal at egenix.com
Fri Jul 8 23:46:22 CEST 2005


Nick Coghlan wrote:

OK, here's some draft documentation using Phillip's context terminology. I think it works very well.

""" With Statements and Context Management A frequent need in programming is to ensure a particular action is taken after a specific section of code has been executed (such as closing a file or releasing a lock). The tool to achieve this in Python is to use the 'with' statement along with the appropriate context manager. Context managers ensure a particular action is taken to establish the context before the contained suite is entered, and a second action to clean up the context when the suite is exited. The precise behaviour of the 'with' statement is governed by the supplied context manager - an object which supports the context management protocol. This protocol consists of two methods:

May I suggest that you use a different name than "context" for this ?!

The term "context" is way to broad for the application scopes that you have in mind here (like e.g. managing a resource in a multi-threaded application).

The PEP talks about "blocks", which is a much more precise term for what "with" is going to implement, so I'd suggest to call these thingies "block managers".

Thanks,

Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, Jul 08 2005)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the Python-Dev mailing list