Because an error occurs in python3
From frame = inspect.currentframe (depth + 1)
Fixed to frame = inspect.currentframe (). f_back
import inspect
import os
def location(depth=0):
frame = inspect.currentframe().f_back
return os.path.basename(frame.f_code.co_filename), frame.f_code.co_name, frame.f_lineno
def func1():
print(location())
def main():
print(location())
func1()
if __name__ == '__main__':
main()
exit(0)
('a.py', 'main', 13)
('a.py', 'func1', 10)
Look up the current filename and line number in Python. --k Somehow Diary http://d.hatena.ne.jp/kwatch/20100410/1270851205
Python Tips: I want to get the name and arguments of the current function --Life with Python http://www.lifewithpython.com/2015/11/python-get-function-name.html
I want to get the name of the function / method being executed --Qiita http://qiita.com/megmogmog1965/items/0b4ea3d58e34f1854158
Recommended Posts