python - 为什么 pdb.set_trace() 不进入下一行,而是进入 interactiveshell.py?
问题描述
我正在使用 pdb.set_trace() +n 单步执行我的代码的每一行。大多数时候它都有效。我现在有一个新代码,并且在 for 循环之前设置了跟踪。当我单击“n”时,它没有进入 For 循环,而是进入了一些 interactiveshell.py 文件:
for item in init_times:
(Pdb) n
> c:\anaconda\lib\site-packages\ipython\core\interactiveshell.py(3329)run_code()
-> sys.excepthook = old_excepthook
如何摆脱这种情况并继续逐行调试我的代码?遍历这个交互式shell 需要很长时间,我不知道它是什么或者我需要在其中调试什么。
这是我在 If 语句之前有跟踪的代码快照:
for item in init_times:
pdb.set_trace()
if item[0]=='From Seconds':
start_0.append(1)
elif item[0]=='To Seconds':
end_last.append(1)
if len(start_0)>0 and len(end_last)>0:
full_range = 1
print('full range')
elif len(start_0)>0 and not len(end_last)>0:
begin_range_at_0 = 1
print('data begins at 0')
elif not len(start_0)>0 and len(end_last)>0:
end_range_at_end = 1
print('data ends at last row')
else:
min_start = int(min(t1_comp_init[0], t1_stat_init[0])) # min_start variable is used in statistics() and comparisons() when both
max_end = int(max(t1_comp_init[0], t2_stat_init[0]))
解决方案
您可以尝试放入pdb.set_trace()
一个函数。
它会很好地工作,就像下面的代码一样:
def s():
pdb.set_trace()
a = "aaa"
b = "bbb"
c = "ccc"
return a + b + c
s()
推荐阅读
- javascript - 升级 Node JS 和 ERR_REQUIRE_ESM:必须使用 import 加载 ES Module: 'inheritsloose.js' of Babel Runtime
- c# - 如何获取 Windows 10 的内容?UWP/C# 中的通知?
- cocoa - WKWebView in Cocoa app can't get the cursor on click
- javascript - 我如何在函数中随机制作一些东西?
- android - 此客户端应用程序未批准回调 URL。可以在您的应用程序设置中调整已批准的回调 URL 怎么办?
- android - 如何让 Android 插件从 Unity 的内部存储中读取 json 文件?
- r - 在 R 中绘制具有 95% 置信区间的阈值/分段/变化点模型
- testing - TestCafe - 如何通过 auth0 登录使用角色
- python - 如何使用 python tornado @gen.coroutine 和长时间运行的函数
- sql - 如何为具有不同键的一组记录生成唯一标识符?