【发布时间】:2020-06-22 19:57:10
【问题描述】:
我有一个使用argparse 执行的 (python3) 脚本。例如:
my_program.py arg0 arg1 arg2=foo
出于调试目的,我希望脚本能够执行并将我留在一个开放的解释器会话中。在 python 解释器中调用脚本的常用方法对我不起作用。例如:
# How to input the program arguments? (arg0 arg1 arg2=foo)
exec(open("my_program.py").read())
# How to inherit the interpreter variables once the program has finished executing?
import subprocess
subprocess.call(["my_program.py", "arg0", "arg1", "arg2=foo"])
# How to input the program arguments? (arg0 arg1 arg2=foo)
import my_program
my_program.main()
在运行并能够输入程序参数后,有没有办法让我的程序的解释器保持打开状态?
【问题讨论】:
-
为什么不使用普通的调试器,比如 pdb 或者 pycharm 调试器?
-
这可能是一个解决方案。我只是对探索结果、导入其他库和操作对象感兴趣,而不是单步执行代码。所以这看起来更自然。
标签: python-3.x argparse