How can I know the name of "caller"

billiejoex gnewsg at gmail.com
Tue Jun 19 17:06:40 EDT 2007


On 19 Giu, 22:50, Stefan Sonnenberg-Carstens
<stefan.sonnenb... at pythonmeister.com> wrote:
> billiejoex schrieb:
>
>
>
> > Hi there,
> > unfortunately, I'm compelled to apply a sort of monkey patching at the
> > code of an existing libreary that I can't modify directly.
> > Here's my question
> > Having such code:
>
> > class test:
>
> >     def caller(self):
> >         self.b()
>
> >     def called(self):
> >         pass
>
> > ...(if it is possible) how can I get, from method "called", the name
> > of function/method that called it (in this case "caller")?
>
> > Thanks in advance
>
> inspect.stack is your friend ;-)- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Thank you man. That's what I was searching for.
This should be production code. Is insepct.stack fast enough?
Considering that I'd have to use inspect.stack inside a 'while'
statement looping different times, I wouldn't slow down my application.




More information about the Python-list mailing list