Creating a local variable scope.

Daniel Stutzbach daniel at stutzbachenterprises.com
Sat Sep 12 15:31:22 CEST 2009


On Fri, Sep 11, 2009 at 8:29 PM, Steven D'Aprano <
steve at remove-this-cybersource.com.au> wrote:

> (4) Create a "do nothing" context manager allowing you to visually indent
> the block, but otherwise have no effect:
>

"with" doesn't create a new scope.  Observe:

Python 2.6.2 (r262:71600, Apr 15 2009, 07:20:39)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> with open('/dev/null') as f:
...   x = 5
...
>>> x
5

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090912/b78386e5/attachment.html>


More information about the Python-list mailing list