如何在 python 脚本结束时启动 REPL?
How to start REPL at the end of python script?
如何在 python 脚本末尾启动 REPL 进行调试?在节点中我可以做这样的事情:
code;
code;
code;
require('repl').start(global);
有python替代方案吗?
只需使用 pdb(python 调试器)
import pdb
print("some code")
x = 50
pdb.set_trace() # this will let you poke around... try "p x"
print("bye")
如果从命令提示符执行此操作,只需使用 -i
:
➜ Desktop echo "a = 50" >> scrpt.py
➜ Desktop python -i scrpt.py
>>> a
50
这会在脚本执行后调用 Python。
或者,只需在脚本中将 PYTHONINSPECT
设置为 True
:
import os
os.environ['PYTHONINSPECT'] = 'TRUE'
如何在 python 脚本末尾启动 REPL 进行调试?在节点中我可以做这样的事情:
code;
code;
code;
require('repl').start(global);
有python替代方案吗?
只需使用 pdb(python 调试器)
import pdb
print("some code")
x = 50
pdb.set_trace() # this will let you poke around... try "p x"
print("bye")
如果从命令提示符执行此操作,只需使用 -i
:
➜ Desktop echo "a = 50" >> scrpt.py
➜ Desktop python -i scrpt.py
>>> a
50
这会在脚本执行后调用 Python。
或者,只需在脚本中将 PYTHONINSPECT
设置为 True
:
import os
os.environ['PYTHONINSPECT'] = 'TRUE'