Logging global assignments

Peter Otten __peter__ at web.de
Fri Mar 11 09:17:22 EST 2005


Jacek Generowicz wrote:

> Inspecting the implementation of execfile suggests to me that the
> assignments are performed by a hard-wired call to PyDict_SetItem, in
> the opcode implementations, so it looks like ideas based on giving
> execfile a globals dictionary with an instrumented __setitem__ are
> probably doomed to failure.
 
For Python 2.4 here is evidence against that assumption:

$ cat config.py
a = 42
b = "so what"


>> class Dict(dict):
...     def __setitem__(self, k, v):
...             print k, "->", v
...             dict.__setitem__(self, k, v)
...
>>> execfile("config.py", Dict())
a -> 42
b -> so what

We are all doomed to succeed, then...

Peter






More information about the Python-list mailing list