3

In the docs of the iPython magic functions it says:

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.

But it doesn't give any examples of how to use the -r option. How do I associate the pstats.Stats object to a variable? using the cell profiler?

edit:

This is not a duplicate because I specifically ask about cell mode, the other questions are about line magic functions. Thomas K answers my question by saying it is not possible. That should be allowed as an answer to my question here which is not an answer to the other questions.

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132

1 Answers1

4

Unfortunately there is not a way to capture a returned value from a cell magic. With a line magic you can do:

a = %prun -r ...

But cell magics have to start at the beginning of the cell, with nothing before them.

Thomas K
  • 39,200
  • 7
  • 84
  • 86