python -i (interactive environment)

Joe JoeSalmeri at hotmail.com
Tue Mar 8 17:39:56 CET 2005


Steve,

Thanks, I knew about that but my question is why is it not working 
consistently?

Joe


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:09Wdncq9i4MjSbDfRVn-uA at comcast.com...
> Joe wrote:
>> Isn't this a bug?
>>
>> Here's the test program:
>>
>> import code
>>
>> def test_func():
>>     lv = 1
>>     print '\n\nBEFORE lv: %s\n' % (lv)
>>     code.interact(local=locals())
>>     print '\n\nAFTER  lv: %s\n' % (lv)
>>     return
>
> Check the documentation for locals() [1]:
>
> "Update and return a dictionary representing the current local symbol 
> table. Warning: The contents of this dictionary should not be modified; 
> changes may not affect the values of local variables used by the 
> interpreter."
>
> So if you change things in the dictionary returned by locals() you won't 
> actually change the local variables.
>
> STeVe
>
> [1] http://docs.python.org/lib/built-in-funcs.html#l2h-45 





More information about the Python-list mailing list