Logging global assignments
__peter__ at web.de
Fri Mar 11 15:17:22 CET 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...
More information about the Python-list