0

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?

Lucas Myers
  • 366
  • 2
  • 13

1 Answers1

0

%prun docs has this note:

    .. versionchanged:: 7.3
       User variables are no longer expanded,
       the magic line is always left unmodified.

I'm not sure where the expansion is normally done, but prun now uses

opts, arg_str = self.parse_options(parameter_s, 'D:l:rs:T:q',
                                       list_all=True, posix=False)

to handle the arguments.

%history on the other hand uses

@magic_arguments
@argument...
args = parse_argstring(self.history, parameter_s)

Without getting into details, that's a different parsing route.

I have version IPython 7.16.1

%debug, %time and %timeit have 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."

hpaulj
  • 221,503
  • 14
  • 230
  • 353