gpt4 book ai didi

python - python 检查模块 python 的问题

转载 作者:行者123 更新时间:2023-11-30 23:52:37 27 4
gpt4 key购买 nike

如何编写一个程序来“识别函数调用的行号?”

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com