python - python 检查模块 python 的问题

标签 python

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

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/

相关文章:

python - 数组 Python 的复杂子集和合并

python - 模拟 Excel sumifs/多标准索引与 python/pandas 中的数据帧匹配

python - 为什么我的字符串中出现不需要的换行符?

python - 是否有更快的方法来查找数据框中常量值的范围?

python - Pandas 根据条件返回索引和列名

python - 非线性数据上的 k-NN + 降维

python - python中的单词n-gram句子列表

python - 在Python中,为什么 "' a'和 'b'和 'c'“是 'c',而 "' a'或 'b'或 'c'”是 'a'?

python - 如何通过某个键出现的次数来 "sort"字典?

python - 如何使用 ZeroMQ 通过 TCP 套接字发送 PNG 图像?