Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

locals() different behaviour when tracing?

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


anders at 0x63

Oct 8, 2009, 6:43 AM

Post #1 of 3 (1102 views)
Permalink
locals() different behaviour when tracing?

Is it intentional that locals() returns a copy/snapshot of the local
variables sometimes, and sometimes a reference? Like when enabling
tracing, such as in the code pasted below. The documentation ("Update
and return a dictionary containing the current scope's local
variables.") is pretty unclear.

import sys

def X():
l = locals()
i = "foo"
print "Is 'i' in stored locals()? ", ('i' in l)

print "Running normally"
X()

print "Enabling tracing"
def t(*a):
return t
sys.settrace(t)
X()

_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


benjamin at python

Oct 8, 2009, 7:21 AM

Post #2 of 3 (996 views)
Permalink
Re: locals() different behaviour when tracing? [In reply to]

2009/10/8 Anders Waldenborg <anders [at] 0x63>:
>
> Is it intentional that locals() returns a copy/snapshot of the local
> variables sometimes, and sometimes a reference? Like when enabling tracing,
> such as in the code pasted below. The documentation ("Update and return a
> dictionary containing the current scope's local variables.") is pretty
> unclear.

Yes, it does, and that's why the documentation says changing it is undefined. :)


--
Regards,
Benjamin
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


solipsis at pitrou

Oct 8, 2009, 8:38 AM

Post #3 of 3 (986 views)
Permalink
Re: locals() different behaviour when tracing? [In reply to]

Anders Waldenborg <anders <at> 0x63.nu> writes:
>
> Is it intentional that locals() returns a copy/snapshot of the local
> variables sometimes, and sometimes a reference? Like when enabling
> tracing, such as in the code pasted below.

Since someone else opened a bug, I answered there. Anyone, feel free to correct
me if my answer is wrong.
http://bugs.python.org/issue7083

Regards

Antoine.


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.