A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-February/033287.html below:

New syntax threads -- summary wanted)

[Python-Dev] Pre-PEP: with syntax (was: New syntax threads -- summary wanted) [Python-Dev] Pre-PEP: with syntax (was: New syntax threads -- summary wanted)Samuele Pedroni pedronis@bluewin.ch
Mon, 10 Feb 2003 16:36:49 +0100
>'with' [ var '=' ] expr ':'
>    suite
>
>    This statement is defined as being equivalent to the following
>    sequence of statements:
>
>var = expr
>
>if hasattr(var, "__enter__"):
>    var.__enter__()
>
>try:
>    suite
>
>finally:
>    if hasattr(var, "__exit__"):
>var.__exit__()
>
>    If the variable is omitted, an unnamed object is allocated on the
>    stack.  In that case, the suite has no access to the unnamed object.

I would not really depend when var is specified, that its binding is not
modified in suite,
I would store expr result away and use that:

var = _secret = expr

... rest of impl uses _secret not var ...

Less fragile.

regards




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4