Sort of an odd way to debug...

xkenneth xkenneth at gmail.com
Tue Sep 4 15:18:23 EDT 2007


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!




More information about the Python-list mailing list