I am often asked to debug Python scripts written by others. I would like to send these scripts to IPython so it will drop into an IPython shell at the point the script fails.
Unfortunately, I cannot find a way to send (required) command-line options required by the scripts.
IPython assumes everything in is for IPython when I pass the script and its options as:
ipython <script_name> <script_options>
Is there a solution or workaround?
I know there's an already accepted solution, but in the most recent version of ipython this won't work. Here's a cut and paste of the command I use to run tornado tests with --autoreload
This is using ipython .11.
Simple example here.
script.py
shell:
Many aspects of IPython's behavior can be controlled via settings in the user's IPython config files, which typically are in
~/.ipython/
. A user can create multiple profiles, each with different settings of the config parameters. Each profile has its settings in a separate folder in the.ipython
folder. The default profile is inprofile_default
, and the main file in there for customizing behavior isipython_config.py
. By default, it is almost entirely commented, with commented lines showing the config variables and their default settings. Uncomment or insert lines to alter behavior.To change how IPython behaves at the end of running a script, use:
Then when the script ends (or raises an exception), IPython will keep running and present you with a prompt. This is the same behavior as
ipython -i
.I use this setting in my default profile, because this is the way I always want IPython to behave. If that's not the case for you, you could create a profile with this behavior, to use just when you want this behavior. Or just keep using the (evidently undocumented)
-i
option.IPython configuration documentation is available here: Introduction to IPython configuration — IPython documentation, with the
force_interact
option described here: Terminal IPython options — IPython documentation.