TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Python Mystery

30 pointsby dcrostaabout 13 years ago

3 comments

revelationabout 13 years ago
The issue seems to be that CPython is optimizing the locals access for the exec_code_object_and_return_x by using indices into the array, instead of the normal lookup by name (which, by incident, is what the compiled code uses).<p>If I understand <a href="http://bugs.python.org/issue4831" rel="nofollow">http://bugs.python.org/issue4831</a> correctly, CPython 2.7 should not be optimizing the locals access in this way with an exec statement present.
maxk42about 13 years ago
Is it possible x is referring to the memory where x had previously been allocated?
评论 #3911586 未加载
halayliabout 13 years ago
Speaking of CPython optimizations<p>&#62; x = 124236<p>&#62; y = 124237<p>&#62; y -= 1<p>&#62; id(x)<p>140474467900408<p>&#62; id(y)<p>140474467900360<p>&#62; x is y<p>False<p>&#62; x = 1<p>&#62; y = 2<p>&#62; y -= 1<p>&#62; id(x)<p>140558102245816<p>&#62; id(y)<p>140558102245816<p>&#62; x is y<p>True
评论 #3911813 未加载
评论 #3911819 未加载