How do I run the REPL at the end of a python script?

How can I run the REPL at the end of a python script for debugging? In Node, I can do something like this:

code;
code;
code;

require('repl').start(global);

      

Is there a python alternative?

+3


source to share


2 answers


If you do this from the command line, just use -i

:

โžœ Desktop echo "a = 50" >> scrpt.py
โžœ Desktop python -i scrpt.py 
>>> a
50

      

this calls Python after the script is executed.



Alternatively, just set PYTHONINSPECT

in True

in your script:

import os
os.environ['PYTHONINSPECT'] = 'TRUE'  

      

+2


source


Just use pdb (python debugger)



import pdb
print("some code")
x = 50
pdb.set_trace() # this will let you poke around... try "p x"
print("bye")

      

+2


source







All Articles