[Edu-sig] looking for explanations... globals dynamic dict

kirby urner kirby.urner at gmail.com
Mon Mar 28 22:48:05 CEST 2011

On Mon, Mar 28, 2011 at 1:29 PM, Laura Creighton <lac at openend.se> wrote:

> In a message of Mon, 28 Mar 2011 11:19:45 PDT, kirby urner writes:
> >--===============0915739999==
> >Content-Type: multipart/alternative; boundary=20cf303b3f9bfa4ea5049f8efcd
> >What I less understand is why g isn't just a *snap shot* of what was
> global
> >at the time globals( ) ran.
> Because you didn't bind g to a copy of the global dictionary at time t.
> You bound it to the global dictionary itself.
> Laura

Yes, and the contents of that dict change as a side effect of assignment in
the global namespace.

When I bind to dir( ) at time t, there's no mutating dict on the other end
of the line, just a snap shot.

>>> ================================ RESTART
>>> d = dir()
>>> d
['__builtins__', '__doc__', '__name__', '__package__']
>>> v = 14
>>> d
['__builtins__', '__doc__', '__name__', '__package__']
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'd', 'v']

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20110328/861f6d09/attachment.html>

More information about the Edu-sig mailing list