Variable scope and caller

Ben Leslie benno at sesgroup.net
Sun Dec 15 17:00:05 EST 2002


On Sun, 15 Dec 2002, Erik Lechak wrote:

> Hello All,
> 
> Before I get to my question, I would just like to thank the people
> that responded to my "perl to python" post.  I appreciated all the
> info.  And I only had one person preach about the evils of perl.  The
> way python handles documentation is awesome.  Reading non POD
> documentation is a joy.
> 
> Here is my question.  In the following code, I want to be able to find
> the value for 'y' in the function pstring.__str__.  Note that 'y'
> exists in the scope of the calling function.
> 
> 1)  How do I find the function that called me?

It is debatable as to whether this is a good idea, but you probably want the
inspect module:

http://www.python.org/doc/current/lib/inspect-stack.html.

There was a thread about a month ago on this that goes into detail.

Cheers,

Benno




More information about the Python-list mailing list