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

How do I assign the result of iPython profiler %%prun -r to a variable?

在 iPython 魔法函数的 docs 中它说:

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 ...

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