I am writing my script interactively with IPython. This is what I currently do:
Is there more efficient way? Can I start a script from a specific line while using all the variables in current namespace?
I'd personally also use the ipython notebook, but you call also use you favorite text editor and always copy out the chunk of code you want to run and use the magic command %paste to run that chunk in the ipython shell. It will take care of indentation for you.
Use the magic of %edit stuff.py
(first use) and %ed -p
(after the first use) and it will invoke your $EDITOR
from inside of ipython. Upon exiting from the editor ipython will run the script (unless you called %ed -x
). That is by far the fastest way I found to work in CLI-ipython. The notebooks are nice, but I like having a real editor for code.
Use ipdb ("pip install ipdb" on the command line to install it).
Suppose you want to run script "foo.py" from line 18 to 23. You'll want to start like this:
ipdb foo.py
Now, let's jump to line 18 (i.e., ignore all the lines before the 18th):
ipdb> j 18
Next, we set a breakpoint at line 23 (we don't want to go further):
ipdb> b 23
Finally, let's execute:
ipdb> c
Job done :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With