python - 如何将 iPython 探查器 %%prun -r 的结果分配给变量?

标签 python profiling ipython ipython-magic

docs它说的 iPython 魔法函数:

Usage, in cell mode: %%prun [options] [statement] code... code...

In cell mode, the additional code lines are appended to the (possibly empty) statement in the first line. Cell mode allows you to easily profile multiline blocks without having to put them in a separate function.

Options: -r return the pstats.Stats object generated by the profiling. This object has all the information about the profile in it, and you can later use it for further analysis or in other functions.

但是它没有给出任何如何使用 -r 选项的例子。如何将 pstats.Stats 对象关联到变量?使用细胞分析仪?

编辑:

这不是重复的,因为我专门询问单元模式,其他问题是关于线魔术功能。Thomas K 回答我的问题说这是不可能的。这应该被允许作为我在这里的问题的答案,而不是对其他问题的答案。

最佳答案

不幸的是,没有办法从单元魔法中捕获返回值。使用线条魔术,您可以:

a = %prun -r ...

但细胞魔法必须从细胞的开头开始,之前没有任何东西。

关于python - 如何将 iPython 探查器 %%prun -r 的结果分配给变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36773106/

相关文章:

python - 在python中矢量化特征散列

python - 删除 pandas 数据框中的所有数据

python - 使用 Tweepy 给自己发送电子邮件提醒。但是电子邮件内容正在累积每条推文。我想让它覆盖

node.js - 使用 --inspect 分析 NodeJS 时, "(program)"是什么意思

java - 调用垃圾回收会导致程序在java中使用较少的堆内存

python - 在不关闭的情况下分离 ipython notebook 进程?

python - 子进程命令编码

java - NetBeans Profiler 上的 byte[] 和 char[]

python - 如何从终端运行 .ipynb Jupyter Notebook?

ipython - 在 IPython 中存储宏