Skip to content

Instantly share code, notes, and snippets.

@recall704
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recall704/dcd59fa8b1ea1f5346c0 to your computer and use it in GitHub Desktop.
Save recall704/dcd59fa8b1ea1f5346c0 to your computer and use it in GitHub Desktop.
Getting the caller function name inside another function in Python?
i am function g
i am function f
('my parent function is', 'g')
i am function k
i am function f
('my parent function is', 'k')
#coding:utf-8
import inspect
def f():
print('i am function f')
print('my parent function is',inspect.stack()[1][3])
def g():
print('i am function g')
f()
def k():
print('i am function k')
f()
g()
k()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment