ipython use "%run" to execute a subset of a file

98 Views Asked by At

Is there some way I can use %run to execute a subset of a file?

Something like this:

$ ipython
In [1]: %run my_code.py -L 20 100 # executes lines 20-100 in ipython interpereter
1

There are 1 best solutions below

0
On BEST ANSWER

%run doesn't have an option for this. You can see all the options it takes by doing %run? inside IPython.

However, you can bring a specific range of lines from a file into the interactive prompt, and run it from there. The syntax to do this looks like:

%load -r 20-100 my_code.py