Author pitrou
Recipients andbj, pitrou
Date 2009-10-08.15:37:19
SpamBayes Score 0.00012397
Marked as misclassified No
Message-id <1255016241.2.0.789061159118.issue7083@psf.upfronthosting.co.za>
In-reply-to
Content
The same is thing is true of the frame's f_locals attribute. This
attribute is a copy of the local variables in the frame, because the
internal storage of these variables is a raw C array for faster access.
This copy is only synchronized back when a tracing function returns, so
as to allow implementing a debugger.

>>> def f():
...   a = 1
...   l = sys._getframe().f_locals
...   b = 2
...   return l
... 
>>> f()
{'a': 1}

The above optimization (raw C array for faster access of local
variables) is not done at the global scope, and therefore locals() at
that scope give you direct access to the variables' internal store
(which is, actually, the module's __dict__).

>>> import __main__
>>> __main__.__dict__ is locals()
True
History
Date User Action Args
2009-10-08 15:37:21pitrousetrecipients: + pitrou, andbj
2009-10-08 15:37:21pitrousetmessageid: <1255016241.2.0.789061159118.issue7083@psf.upfronthosting.co.za>
2009-10-08 15:37:19pitroulinkissue7083 messages
2009-10-08 15:37:19pitroucreate