While in a Jupyter Notebook I am trying to save the result of the IPython %%prun magic function to a specific file which lives in a subfolder of the current directory, say filename = r'subfoler\profile_result.txt'. I would like to be able to link this file name via
%%prun -T filename
...
However, when I do this, it just prints the profiler output to a file called filename in the current directory. This question has a similar problem, for which the solution is to pass in the variable via $filename. This does not work, and instead just saves the output to a file called $filename. Is this a bug, is it not possible to do what I want, or am I incorrectly passing in the python variable?
%prundocs has this note:I'm not sure where the expansion is normally done, but
prunnow usesto handle the arguments.
%historyon the other hand usesWithout getting into details, that's a different parsing route.
I have version IPython 7.16.1
%debug,%timeand%timeithave the same note.The relevant pull-request: https://github.com/ipython/ipython/pull/11516/
The reasoning: "Most useful for magics that take Python code on the line, e.g. %timeit, etc."