How can I get the function's caller?

D

David

Inside a function I need to get the function's caller's name. How can I get
it?

thanks in advance.

David
 
S

Steve Holden

David said:
Inside a function I need to get the function's caller's name. How can I get
it?

thanks in advance.

The "function caller", like most objects in Python, needn't actually
have a name. It could, for example, be a lambda stored as a list element.

What do you need this name for, just as a materr of interest? There are
ways of manipulating the stack frames, but they'll be slow and possibly
unreliable.

regards
Steve
 
J

John Machin

David said:
Inside a function I need to get the function's caller's name. How can I get
it?

Check out the thread "__LINE__ and __FILE__ functionality in Python?"
(messages posted 2006-0813).
 
D

David

Il Wed, 13 Sep 2006 07:34:45 +0100, Steve Holden ha scritto:
What do you need this name for, just as a materr of interest? There are
ways of manipulating the stack frames, but they'll be slow and possibly
unreliable.
I am writing a big (for me) program and it would be helpful to have a dummy
function like this:

def function_A_subfunction_B(self, ....)
dummy()

that display a standard message like this:

"Dummy: 'function_A_subfunction_B' in module 'module' is not defined yet"

regards
David
 
D

David

Il 13 Sep 2006 00:31:47 -0700, John Machin ha scritto:
Check out the thread "__LINE__ and __FILE__ functionality in Python?"
(messages posted 2006-0813).

I'll check thankyou!
Traffic in this NG is so high that is difficult to stay uptodate.

David.
 
M

Michele Simionato

David said:
Il Wed, 13 Sep 2006 07:34:45 +0100, Steve Holden ha scritto:

I am writing a big (for me) program and it would be helpful to have a dummy
function like this:

def function_A_subfunction_B(self, ....)
dummy()

that display a standard message like this:

"Dummy: 'function_A_subfunction_B' in module 'module' is not defined yet"

regards
David

Check also the warnings module (it will give you also line number
information for free).

Michele Simionato
 
S

Steve Holden

David said:
Il Wed, 13 Sep 2006 07:34:45 +0100, Steve Holden ha scritto:



I am writing a big (for me) program and it would be helpful to have a dummy
function like this:

def function_A_subfunction_B(self, ....)
dummy()

that display a standard message like this:

"Dummy: 'function_A_subfunction_B' in module 'module' is not defined yet"
One way would be to have dummy() raise an exception, which it catches.
Then use the traceback information to provide the information you want.

regards
Steve
 
F

Fredrik Lundh

David said:
I am writing a big (for me) program and it would be helpful to have a dummy
function like this:

def function_A_subfunction_B(self, ....)
dummy()

that display a standard message like this:

"Dummy: 'function_A_subfunction_B' in module 'module' is not defined yet"

that's spelled

def function_A_subfunction_B(self, ....)
raise NotImplementedError

in Python.

</F>
 
J

John Machin

David said:
Il 13 Sep 2006 00:31:47 -0700, John Machin ha scritto:


I'll check thankyou!
Traffic in this NG is so high that is difficult to stay uptodate.

You don't need to. Google is your friend. Google "caller name" in this
NG; it's that simple :)

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top