python - 如何将文件加载到 python 控制台中?

标签 python read-eval-print-loop

我有一些 Python 代码行,我不断地将它们复制/粘贴到 Python 控制台中。是否有 load 命令或我可以运行的东西?例如加载文件.py

最佳答案

来自手册页:

-i When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command. It does not read the $PYTHONSTARTUP file. This can be useful to inspect global variables or a stack trace when a script raises an exception.

所以这应该做你想要的:

python -i file.py

关于python - 如何将文件加载到 python 控制台中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280178/

相关文章:

scala - 如何保存 REPL session ?

scheme - 如何向上滚动到 mit-scheme REPL 中的最后一个条目?

python - 如何更改 False 列表中的所有 True 值,反之亦然

python - 从 S3 django 下载多个文件

python - 运行 ffmpeg 时 Popen.communicate() 仅返回 err

emacs - 如何在苹果酒模式下清除 REPL?

cocoa - 在 Cocoa 程序中访问 Swift REPL

python - Pandas 每行获得前 n 列

python - 自动化无聊的事情 - 逗号代码 : Why doesn't my code work?

language-agnostic - 一个 REPL 将它们全部绑定(bind)?