Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start REPL at the end of python script?

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

code;
code;
code;

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

Is there any python alternative?

like image 783
Lapsio Avatar asked Jul 27 '17 08:07

Lapsio


2 Answers

If you execute this from the command prompt, just use -i:

➜ Desktop echo "a = 50" >> scrpt.py
➜ Desktop python -i scrpt.py 
>>> a
50

this invokes Python after the script has executed.

Alternatively, just set PYTHONINSPECT to True in your script:

import os
os.environ['PYTHONINSPECT'] = 'TRUE'  
like image 91
Dimitris Fasarakis Hilliard Avatar answered Oct 18 '22 03:10

Dimitris Fasarakis Hilliard


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")
like image 36
Yoav Glazner Avatar answered Oct 18 '22 02:10

Yoav Glazner