gpt4 book ai didi

Python 模块 "trace": file path missing

转载 作者:太空狗 更新时间:2023-10-29 17:50:42 25 4
gpt4 key购买 nike

我正在跟踪这样一个 python 脚本:

python -m trace --ignore-dir=$HOME/lib64:$HOME/lib:/usr -t bin/myscript.py

一些行看起来像这样:

 --- modulename: __init__, funcname: getEffectiveLevel
__init__.py(1325): logger = self
__init__.py(1326): while logger:
__init__.py(1327): if logger.level:
__init__.py(1329): logger = logger.parent
__init__.py(1326): while logger:
__init__.py(1327): if logger.level:
__init__.py(1328): return logger.level

不幸的是,我不知道这段代码是从哪里来的。

有没有办法查看getEffectiveLevel()的文件名(包括路径)?

当然,我可以在所有已安装的 Python 代码中搜索具有此名称的方法,但我想立即查看文件路径。

在此上下文中,使用了 Python 2.7

I am not fixed to the standard library "trace". I could use a different library, if it provides the needed feature.

最佳答案

如果目的是找到完整路径,则检查 hunter项目,它甚至支持 query-style追踪。

# a modified example from docs
# do check the documentation it is easy to start with
from hunter import trace, Q, Debugger
from pdb import Pdb

trace(
# drop into a Pdb session on``myscript.mainMethod()`` call
Q(module="myscript", function="getEffectiveLevel", kind="call", action=Debugger(klass=Pdb)))

import myscript
myscript.mainMethod()

关于Python 模块 "trace": file path missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50598438/

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