如何从执行开始到结束跟踪我的 python 程序? [英] How do I trace my python program from start of execution to finish?

查看:58
本文介绍了如何从执行开始到结束跟踪我的 python 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用python编写的函数,我想从头到尾一步一步地检查它是如何运行的.我该怎么做?

I have a function written in python, and I want to inspect how it runs step by step from start to finish. How do I go about doing this?

我使用 PyCharm 作为 IDE,但我不知道它是否具有跟踪功能.

I am using PyCharm as an IDE, but I don't know if it has a tracing feature.

在这个问题上有任何对新手友好的提示或资源吗?

Any tips or resources that are newbie friendly on this issue?

非常感谢!

推荐答案

如果您在 PyCharm 中运行您的代码,只需设置一个 breakpoint 在您希望检查的函数的第一行,然后使用他们的界面逐步执行.

If you're running your code within PyCharm, simply set a breakpoint on the first line within the function you wish to examine, then step through it using their interface.

如果您通过命令行运行代码,我强烈建议您熟悉 Python 的调试模块,pdb.检查函数所需要做的就是临时添加以下行:

If you're running your code via the commandline, I highly recommend familiarizing yourself with Python's debugging module, pdb. All you need to do to examine your function is temporarily add the line:

import pdb;pdb.set_trace()

.. 作为函数的第一行.当您运行它并遇到这一行时,您可以使用简单的指令(如n"表示下一行)在命令行上逐步执行.

.. as the first line of your function. When you run it and it hits this line, you can step through the execution on the commandline using simple directives like 'n' for next line.

这篇关于如何从执行开始到结束跟踪我的 python 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆