How can I know the name of "caller"

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Jun 19 22:46:59 EDT 2007


En Tue, 19 Jun 2007 18:06:40 -0300, billiejoex <gnewsg at gmail.com> escribió:

> On 19 Giu, 22:50, Stefan Sonnenberg-Carstens
> <stefan.sonnenb... at pythonmeister.com> wrote:
>> billiejoex schrieb:
>>
>>
>> > ...(if it is possible) how can I get, from method "called", the name
>> > of function/method that called it (in this case "caller")?
>>
>> inspect.stack is your friend ;-)- Nascondi 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.

A faster way is to use sys._getframe(1).f_code.co_name
But it doesn't feel good for production code... can't you find a different  
approach?

-- 
Gabriel Genellina




More information about the Python-list mailing list