How to Load a .py File in the Python Interactive Shell for Debugging?

  • Context: Python 
  • Thread starter Thread starter sid_galt
  • Start date Start date
  • Tags Tags
    File Python Shell
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 22K views
sid_galt
Messages
503
Reaction score
1
How can I load a .py file in the python interactive shell for debugging?
 
Physics news on Phys.org
If you open the python interpreter by typing:

python -i filename.py

It will execute filename.py and then drop you into interactive mode with the environment left behind by filename.py.

I sometimes build this directly into my scripts, for example by beginning with:

#!/usr/bin/python -i