How to drop into REPL (Read, Eval, Print, Loop) from Python code Ask Question

How to drop into REPL (Read, Eval, Print, Loop) from Python code Ask Question

Is there a way to programmatically force a Python script to drop into a REPL at an arbitrary point in its execution, even if the script was launched from the command line?

I'm writing a quick and dirty plotting program, which I want to read data from stdin or a file, plot it, and then drop into the REPL to allow for the plot to be customized.

ベストアンサー1

I frequently use this:

def interact():
    import code
    code.InteractiveConsole(locals=globals()).interact()

おすすめ記事