Logging global assignments

Jacek Generowicz jacek.generowicz at cern.ch
Fri Mar 11 07:53:39 EST 2005


I am dealing with an application which reads in configurations by
calling (a wrapper around) execfile. Any configuration file may itself
execfile other configuration files in the same manner.

I would like to create a log containing all global assignments made in
these files. Comparing the globals dictionaries before and after is
not quite enough, as 

a) this misses multiple assignments to the same name, within a single
   file,

b) doesn't allow me to pinpoint the line at which the assignment is
   made.

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.

Is there any way of injecting some of my code into the process of
global name binding, or some other means of "capturing" global
assignments ?



More information about the Python-list mailing list