Re: updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))

2004-12-09 Thread Bengt Richter
On Wed, 8 Dec 2004 20:22:52 -0500, Terry Reedy [EMAIL PROTECTED] wrote: To respond to and summarize several posts in this discussion: Within a function, where the local namespace is distinct from the global (module) namespace, CPython usually implements the local namespace internally as a

Re: updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))

2004-12-08 Thread Caleb Hattingh
Steve, I don't think I understand. Here is what I just tried: ' def f(): x = 3 d = locals() print x print d['x'] d['x'] = 5 print x ' f() 3 3 3 ' In your example, x had not yet been initialised, maybe. What I am seeing is that x does not

Re: updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))

2004-12-08 Thread Steven Bethard
Caleb Hattingh wrote: Steve, I don't think I understand. Here is what I just tried: ' def f(): x = 3 d = locals() print x print d['x'] d['x'] = 5 print x ' f() 3 3 3 ' In your example, x had not yet been initialised, maybe. What I am seeing is that x does not seem

Re: updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))

2004-12-08 Thread Jeff Shannon
Steven Bethard wrote: I remember hearing an explanation of why locals() is not writable that had to do with something about efficiency and the call stack (or something like that)... IIRC, the function local namespace (in CPython) is kept internally as a static array, rather than as a

Re: updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))

2004-12-08 Thread Terry Reedy
To respond to and summarize several posts in this discussion: Within a function, where the local namespace is distinct from the global (module) namespace, CPython usually implements the local namespace internally as a fixed-length array. When this is true, locals() is a *copy* of the local