ソースファイルの行番号をprintで出力したい

Python

import inspect def location(depth=0): # frame = inspect.currentframe(depth+1) frame = inspect.currentframe() return (frame.f_code.co_filename, frame.f_lineno) # if __name__ == '__main__':# def f():# g() def g(): print(location(1)) # print(location(1)) # print(location(2)) print (117, __file__)g()print(119, __file__, location())

コメントを投稿

0 コメント