Showing content from http://mail.python.org/pipermail/python-dev/attachments/20070207/89e064ec/attachment.html below:
On 2/7/07, <b class="gmail_sendername">Greg Ewing</b> <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Fabio Zadrozny wrote:<br><br>> frame = findFrame(thread_id, frame_id)<br>> exec '%s=%s' % (attr, expression) in frame.f_globals, frame.f_locals<br><br>The locals of a function are actually stored in an array.
<br>When you access them as a dict using locals(), all you<br>get is a dict containing a copy of their current values.<br>Modifying that dict doesn't affect the underlying array.<br><br>It seems that reading the f_locals of a frame does the
<br>same thing. To modify the locals, you would need to poke<br>values into the original array -- but it doesn't seem<br>to be exposed to Python.<br><br>So it looks like you're out of luck.<br></blockquote></div><br>
Would it be ok to add a feature request for that? I initially thought it was completely read-only, but I find it strange that it affects the topmost frame correctly (so, it seems that even though I get a copy, when I alter that copy on the topmost frame it affects it correctly)... anyone has a clue why that happens?
<br><br>It seems to affect pdb too...<br><br>Consider the code:<br>if __name__ == '__main__':<br> <br> def call1():<br> v_on_frame1 = 10<br> print 'v_on_frame1', v_on_frame1<br>
<br> def call0():<br> import pdb;pdb.set_trace()<br> v_on_frame0 = 10<br> call1()<br> print 'v_on_frame0', v_on_frame0<br> <br> call0()<br> <br> <br>#when modifying in the current frame
<br>> x:\scbr15\source\python\tests_base\empty_test.py(9)call0()<br>-> v_on_frame0 = 10<br>(Pdb) n<br>> x:\scbr15\source\python\tests_base\empty_test.py(10)call0()<br>-> call1()<br>(Pdb) v_on_frame0 = 40<br>(Pdb) c
<br>v_on_frame1 10<br>v_on_frame0 40<br><br><br><br>#when modifying an upper frame it does not work<br>> x:\scbr15\source\python\tests_base\empty_test.py(9)call0()<br>-> v_on_frame0 = 10<br>(Pdb) n<br>> x:\scbr15\source\python\tests_base\empty_test.py(10)call0()
<br>-> call1()<br>(Pdb) s<br>--Call--<br>> x:\scbr15\source\python\tests_base\empty_test.py(3)call1()<br>-> def call1():<br>(Pdb) n<br>> x:\scbr15\source\python\tests_base\empty_test.py(4)call1()<br>-> v_on_frame1 = 10
<br>(Pdb) u<br>> x:\scbr15\source\python\tests_base\empty_test.py(10)call0()<br>-> call1()<br>(Pdb) v_on_frame0 = 40<br>(Pdb) d<br>> x:\scbr15\source\python\tests_base\empty_test.py(4)call1()<br>-> v_on_frame1 = 10
<br>(Pdb) c<br>v_on_frame1 10<br>v_on_frame0 10<br><br><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