任何 IDE 中是否有调试功能可以让您查看 "path" 您的代码占用了什么?
Is there a debugging feature in any IDE that lets you see what "path" your code took?
所以我正在调试一大段代码,这是一项艰巨的任务。该代码涉及许多条件 (if/else) 语句,并且为了使此调试工作更容易,我想看看 "path" 解释器通过所有 if/elses.
例如:
if stuff:
x = "stuff"
elif otherstuff:
x = "otherstuff"
else:
x = "evenmorestuff"
return x
我的实际代码比这复杂得多,用 return
代替 x
不是一种选择。但我希望你能明白。
我想看看 "path" 通过 ifs、elifs 和 elses 我的代码在崩溃时采取了什么。例如:
| if stuff:
> x = "stuff" (ran this line)
| if morestuff:
| y = "morestuff" (skipped this line)
| else:
> y = "nostuff" (ran this line)
|elif otherstuff:
| x = "otherstuff" (skipped this line)
|else:
| x = "evenmorestuff" (skipped this line)
>return x (ran this line)
在 IDE 中是否有任何功能可以做到这一点? (我正在使用 Visual Studio Community 2015 with PTVS 和 Python,所以如果有解决方案,那就太好了,因为我不必切换 IDEs。)我只是不知道它会叫什么,当我搜索类似这个标题的东西时,google 搜索没有结果,所以我决定在这里问。
谢谢:)
您要查找的动词是"tracing"。
Python 有一个 trace
模块可以做到这一点。我找到了关于
tracing in general and the module itself 看起来很有用。
The trace module helps you understand the way your program runs. You can trace the statements executed, produce coverage reports, and investigate the relationships between functions that call each other.
您可能会发现将代码重构为更小的函数可以更容易理解and/or跟踪其执行。
所以我正在调试一大段代码,这是一项艰巨的任务。该代码涉及许多条件 (if/else) 语句,并且为了使此调试工作更容易,我想看看 "path" 解释器通过所有 if/elses.
例如:
if stuff:
x = "stuff"
elif otherstuff:
x = "otherstuff"
else:
x = "evenmorestuff"
return x
我的实际代码比这复杂得多,用 return
代替 x
不是一种选择。但我希望你能明白。
我想看看 "path" 通过 ifs、elifs 和 elses 我的代码在崩溃时采取了什么。例如:
| if stuff:
> x = "stuff" (ran this line)
| if morestuff:
| y = "morestuff" (skipped this line)
| else:
> y = "nostuff" (ran this line)
|elif otherstuff:
| x = "otherstuff" (skipped this line)
|else:
| x = "evenmorestuff" (skipped this line)
>return x (ran this line)
在 IDE 中是否有任何功能可以做到这一点? (我正在使用 Visual Studio Community 2015 with PTVS 和 Python,所以如果有解决方案,那就太好了,因为我不必切换 IDEs。)我只是不知道它会叫什么,当我搜索类似这个标题的东西时,google 搜索没有结果,所以我决定在这里问。
谢谢:)
您要查找的动词是"tracing"。
Python 有一个 trace
模块可以做到这一点。我找到了关于
tracing in general and the module itself 看起来很有用。
The trace module helps you understand the way your program runs. You can trace the statements executed, produce coverage reports, and investigate the relationships between functions that call each other.
您可能会发现将代码重构为更小的函数可以更容易理解and/or跟踪其执行。