![]() |
|
|
+ Search |
![]()
|
Nov 19th, 2008 21:42
Chris Zate, unknown unknown, Alex Martelli
Sure -- piece o' cake...:
def caller(n=1):
from traceback import extract_stack
stack = extract_stack()
return stack[-n-2][2]
# Example usage:
def a():
print "this is", caller(0)
b()
def b():
print "and this is",caller(0),
print "called by",caller()
Expected output by calling a():
http://animaux.leblogguide.com/
http://voyagesingapour.leblogguide.com
http://voyageauperou.leblogguide.com
http://voyageauchili.leblogguide.com
http://italiehotels.leblogguide.com
this is a
and this is b called by a