如何编写一个程序来“识别函数调用的行号?”
python 检查模块提供了定位行号的选项,但是,
def di():
return inspect.currentframe().f_back.f_lineno
此 python 代码打印当前行号。
最佳答案
为什么不使用inspect.stack()
?
def get_caller_lineno():
frame, _, lineno, _, _, _ = inspect.stack()[1]
return lineno
关于python - python 检查模块 python 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6247931/