如何从Python代码放入REPL(读取,评估,打印,循环) [英] How to drop into REPL (Read, Eval, Print, Loop) from Python code

查看:141
本文介绍了如何从Python代码放入REPL(读取,评估,打印,循环)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使脚本是从命令行启动的,有没有办法以编程方式强制Python脚本在执行的任意时刻掉入REPL?

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?

我正在编写一个快速而肮脏的绘图程序,我想从stdin或文件中读取数据,对其进行绘图,然后放入REPL中以自定义绘图.

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.

推荐答案

您可以尝试对python使用交互式选项:

You could try using the interactive option for python:

python -i program.py

这将执行program.py中的代码,然后转到REPL.您在program.py顶层定义或导入的所有内容都将可用.

This will execute the code in program.py, then go to the REPL. Anything you define or import in the top level of program.py will be available.

这篇关于如何从Python代码放入REPL(读取,评估,打印,循环)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆