On 9/4/07, xkenneth <[EMAIL PROTECTED]> wrote: > All, > > Sorry for the vague topic, but I really didn't know how to > describe what I want to do. I'd like to almost do a traceback of my > code for debugging and I thought this would be a really cool way to do > it if possible. > > What I'd like to do, is define a base class. This base class would > have a function, that gets called every time another function is > called (regardless of whether in the base class or a derived class), > and prints the doc string of each function whenever it's called. I'd > like to be able to do this without explicitly specifying the function > inside all of the other functions of a base class or derived class. > > Here's what I think it would look like: > > class Base: > __init__(self,debug=False): > if debug: > self.debug = debug > > def functionThatAlwaysGetsCalled(self): > print self.__docstring__ > > class Derived(Base): > """This function prints something""" > def printSometing(something) > #ghost function get's called here > print something > > Output would be: > This function prints something > something > > Thanks for any help! >
This approach won't work, because you need cooperation from child classes to trigger your printing. A trace function (see sys.settrace) is probably more useful. -- http://mail.python.org/mailman/listinfo/python-list