在Python中打印当前执行代码的行号
可以使用inspect模块中的currentframe()和getframeinfo()函数获取当前所在行号。例如:
import inspect
frame = inspect.currentframe()
print(inspect.getframeinfo(frame).lineno)
这会输出当前代码执行的行号,方便调试。
在Python中打印当前执行代码的行号
可以使用inspect模块中的currentframe()和getframeinfo()函数获取当前所在行号。例如:
import inspect
frame = inspect.currentframe()
print(inspect.getframeinfo(frame).lineno)
这会输出当前代码执行的行号,方便调试。