Created
February 3, 2016 16:01
-
-
Save gt11799/2088c1bd2fd733d5de78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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