在Jupyter Notebook中跟踪语句执行? [英] Trace Statement Execution in Jupyter Notebooks?

查看:131
本文介绍了在Jupyter Notebook中跟踪语句执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Jupyter笔记本中编写一些Python代码,我想知道是否有可能直接在Jupyter中跟踪语句的执行?我知道有一个称为跟踪"的模块: https://docs.python.org/3/library/trace.html#trace.Trace.results 但在我看来,使用"trace"只能在控制台中显示执行流程或导出它到一个新文件.但是,我想直接在Jupyter Notebooks中显示它.在有或没有提到的模块的情况下,这是否可能?如果是,怎么办?

I am currently writing some Python code in a Jupyter notebook and I wonder if there is any possibility to track the execution of statements directly in Jupyter? I know there is this module called "trace": https://docs.python.org/3/library/trace.html#trace.Trace.results But it seems to me that with "trace" it is only possible to show the flow of execution in the console or to export it to a new file. However, I would like to display it directly in Jupyter Notebooks. Is this possible - with or without the mentioned module - and if yes how?

感谢您的帮助.

推荐答案

对于调试代码而言,您可能会对单元魔术 %% debug 感兴趣,已在此处在笔记本中打开调试器并使用pdb 命令.或 PixieDebugger 如果您需要更高级的产品.

For something along the lines of debugging code, you may be interested in the cell magic %%debug, discussed here to open a debugger in the notebook and use pdb commands. Or PixieDebugger if you need something fancier.

您可能还对JupyterLab的变量检查器扩展感兴趣.在此处中有一个使用它的动画示例.您可以通过单击启动活页夹徽章轻松地进行尝试.并启动笔记本.然后右键单击打开的笔记本,然后从列表中选择 Open Variable Inspector .动画将向您展示如何拖动选项卡以在屏幕上并排排列它们.现在,在运行代码时,您将看到变量已更新.

You may also be interested in the variable inspector extension for JupyterLab. There is (old) an animated example of using it here. You can easily try it out by clicking on launch binder badge there and starting a notebook. Then right-click in the open notebook and select Open Variable Inspector from the list. The animation will show you how to drag the tabs to arrange them side by side on your screen. Now as you run code, you'll see the variables updated.

这篇关于在Jupyter Notebook中跟踪语句执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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