What function called this function ?? 
Author Message
 What function called this function ??

Is it possible, by hacking the traceback/stack/etc, to get information about
the function, that functions class and in what module that function and
class are defined, from inside a function located elsewhere? Something like
a way of answering the question of  "who called me?" without sending the
answer along as a parameter.

Best regards,
Thomas



Sun, 13 Mar 2005 21:47:49 GMT  
 What function called this function ??


Quote:
> Is it possible, by hacking the traceback/stack/etc, to get
information about
> the function, that functions class and in what module that function
and
> class are defined, from inside a function located elsewhere?
Something like
> a way of answering the question of  "who called me?" without sending
the
> answer along as a parameter.

Yes.  Traceback hack has been posted previously.  If not in the FAQ,
you might find posts thru groups.google.com.

TJR



Sun, 13 Mar 2005 22:56:15 GMT  
 What function called this function ??

Quote:
> Is it possible, by hacking the traceback/stack/etc, to get
> information about the function, that functions class and in what
> module that function and class are defined, from inside a function
> located elsewhere?  Something like a way of answering the question
> of "who called me?" without sending the answer along as a parameter.

Some variation on this theme:

**

#!/usr/bin/env python

def mycaller():
    """mycaller()

    Return the name of the caller of the caller of this function.
    """
    import sys
    steps_back = 2
    return sys._getframe(steps_back).f_code.co_name

def foo():
    print "foo called by %s." % mycaller()

def bar():
    foo()

bar()

**

Output:

foo called by bar.

// m



Sun, 13 Mar 2005 23:04:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VC++ calling fortran function and fortran function calling a c++ function

2. Calling functions from functions from functions ...

3. How to find out name of calling function from called function

4. Call Library Function - Function not found in library

5. C functions calling {C++/Ada/...} functions

6. Function called from the Listener or from another function

7. Can the 'call library function call code other than c

8. Cross reference/Call structure tools for C function calls

9. calling a function once works, calling it twice fails

10. converting C++ Function to Clarion 5 Function

11. Replace standard MESSAGE function in C4 with own message function

12. Clarion function prototypes for SPGP pgp wrapper functions

 

 
Powered by phpBB® Forum Software