Skip to content

Instantly share code, notes, and snippets.

@gt11799
Created February 3, 2016 16:01
Show Gist options
  • Save gt11799/2088c1bd2fd733d5de78 to your computer and use it in GitHub Desktop.
Save gt11799/2088c1bd2fd733d5de78 to your computer and use it in GitHub Desktop.
'''
To get caller info
'''
import traceback
def func(x):
print "result: %s" % x
stack = traceback.extract_stack()
print "where i am"
item = stack[-1]
print "which file: %s" % item[0]
print "line: %s" % item[1]
print "function name: %s" % item[2]
print "how call: %s" % item[3]
print "\n"
print "where call the function"
item = stack[-2]
print "which file: %s" % item[0]
print "line: %s" % item[1]
print "function name: %s" % item[2]
print "how call: %s" % item[3]
def func1(x):
func(x)
def func2(x):
func1(x)
if __name__ == '__main__':
func2(90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment