Modifying a built-in function for logging purposes

Robert Kern rkern at ucsd.edu
Sat May 14 22:19:08 EDT 2005


qwweeeit at yahoo.it wrote:
> Hi Greg,
> thank for your replay, but I didn't succeed in any way. You must
> consider however that I'm not a Python "expert"...
> IMHO, it must be a script that change part of the interpreter, and
> substitute a new module (py) in the place of the standard one (py or
> pyc). The standard module must be saved in order to be able to undo the
> changes and go back to the normal behaviour.
> The problem is that I don't know if the built-in functions like open
> (or file) are written in Python or in C and, besides that, if they can
> be modified.

Short answer: if you don't know stuff like this, then you probably 
shouldn't mess around with the builtins in production code.

Depending on your operating system, there are probably programs that let 
you list all of the files that have been opened on your system. For 
example, on OS X, lsof(1) does the trick.

> Other solutions which modify the source to be logged, are not
> solutions, because it is far simpler to introduce here and there print
> statements... 

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list