> So things like decimal.Context get left trying to find a sane
> name for what their __context__ method returns.
> decimal.Context.__context__() returns a . . . context? What?
> Wasn't it already a context? Oh, so it actually returns a
> "with statement context object".

[I was OK with "context specifiers", but here is another attempt.]

-----------

With statements execute in a temporary context.

with with_expression as temporary_context_name:
    stmt1
    stmt2


The with_expression must return an object implementing the Temporary
Context protocol.  The Temporary Context's __enter__ method runs
before the statement block, and its __exit__ method runs after the
block.

Temporary Contexts can represent arbitrary changes to the execution
environment.  Often, they just ensure that a file is closed in a
timely fashion.

A more advanced example is Decimal.Context, which controls the
precision of certain math calculations.  Decimal.Context also
implements the Temporary Context protocol, so that you can increase
the precision of a few calculations without slowing down the rest of
the program.

-jJ
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to