A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20100406/ed6abe8d/attachment-0001.html below:

<br><br><div class="gmail_quote">On Tue, Apr 6, 2010 at 11:13 AM, Greg Ewing <span dir="ltr">&lt;<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">Reid Kleckner wrote:<br>


<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If I remember correctly, the exec statement is going away in py3k, and<br>
calling exec() with one argument can modify the local scope.<br>
</blockquote>
<br></div>
I&#39;ve been kind of wondering what the deal is with exec in py3.<br>
I always thought the reason for making exec a statement was so<br>
that locals optimisation could be turned off in its presence,<br>
so I&#39;m not sure how py3 is getting away with making it a<br>
function.<br></blockquote><div><br></div><div>It looks like py3 does not allow exec to modify the locals:</div><div><br></div><div><div>$ python3</div><div>Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) </div><div>[GCC 4.0.1 (Apple Inc. build 5493)] on darwin</div>

<div>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</div><div>&gt;&gt;&gt; def x(a):</div><div>...     exec(a)</div><div>...     return a</div><div>... </div>

<div>&gt;&gt;&gt; x(&quot;a = 5&quot;)</div><div>&#39;a = 5&#39;</div><div>&gt;&gt;&gt; # the above statement would have returned 5 if the locals had been modified</div></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>


Anyhow, it seems to me that as long as locals() or whatever<br>
might replace it is able to find the existing value of a local,<br>
it should also be able to change that value, wherever it<br>
happens to be stored.<br>
<br>
I suppose that might fail if an optimiser decides to keep<br>
multiple copies of a local for some reason, though.<br>
<br>
But even if it has to be read-only, I still think a view object<br>
would be a more py3ish way of handling locals() and the like.<br>
You might only want access to a few locals, in which case<br>
building a dict containing all of them would be wasteful.<br>
<br>
-- <br>
Greg<br>
<br>
<br>
-- <br><font color="#888888">
Greg</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/thobes%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/thobes%40gmail.com</a><br>
</div></div></blockquote></div><br>

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