function call

Chris Mellon arkanes at gmail.com
Tue Sep 4 16:56:29 EDT 2007


On 9/3/07, Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
> ianaré a écrit :
> > Hey all,
> >
> > Is there a way of printing out how a function was called? In other
> > words if I do the following:
> >
> > def someFunction(self):
> >     self.someOtherFunction(var1, var2)
> >
> >
> > I would get something like "someOtherFunction: called by:
> > someFunction, args are: var1, var2"
> >
> > Thanks in advance
> >
> You may be able to solve this using a decorator (to avoid polluting your
> code with this) and the infamous sys._getframe() hack.
> --

Every reasonable use case for this (and several unreasonable ones)
that I've encountered (and some that I've just imagined) can be better
addressed with a trace function (sys.set_trace) than by trying to do
this at the point of call.



More information about the Python-list mailing list