python - 如何使用 python 调试 VSCode 上的 Google Code Jam 交互问题?
问题描述
我尝试下载示例交互式问题数字猜测问题。他们local testing tool
在“描述”选项卡中提供了一个,在“分析”选项卡中提供了一个 python 解决方案,一个同时运行两个脚本的interactive_runner.py 。
将解决方案保存在 a 中后solution.py
,我可以在 shell 上成功运行它python3 interactive_runner.py python3 local_testing_tool.py 0 -- python3 solution.py
:
问题是我无法使用 VSCode 调试它。我尝试将所有 3 个文件放在一个文件夹中并使用以下 launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Arquivo Atual",
"type": "python",
"request": "launch",
"program": "interactive_runner.py python3 local_testing_tool.py 0 -- python3 ${file}",
"console": "integratedTerminal",
}
]
}
当我使用调试器运行solutions.py 时,出现错误:
env DEBUGPY_LAUNCHER_PORT=40453 /home/user/.pyenv/versions/3.8.2/bin/python3.8 /home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher "interactive_runner.py python3 local_testing_tool.py 0 -- python3 /home/user/workspace/wargames/GoogleCodeJam/2018/PracticeSession/NumberGuessing/solution.py"
Traceback (most recent call last):
File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 262, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 232, in _get_code_from_file
with io.open_code(fname) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'interactive_runner.py python3 local_testing_tool.py 0 -- python3 /home/user/workspace/wargames/GoogleCodeJam/2018/PracticeSession/NumberGuessing/solution.py'
关于如何做到这一点有更好的方法吗?
解决方案
该"program"
参数只需要文件的路径,因此有关“没有这样的文件或目录”的错误。您想要做的是获取执行行的其余部分并将它们作为参数:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Arquivo Atual",
"type": "python",
"request": "launch",
"program": "interactive_runner.py",
"console": "integratedTerminal",
"args": ["python3", "local_testing_tool.py", "0", "--", "python3", "${file}"] // Not sure if `${file}` will work here.
}
]
}
推荐阅读
- react-native - 平面列表中的 ReactNative 复选框
- python - 手动实现多元线性回归的 AIC 分数
- arrays - How to print contents of an array containing a class and how to access certain value of the array in Swift
- curl - Filemaker 18 Curl 不发布文件内容
- java - 当我尝试加载 FXML 文件时,出现 java.io.IOException 错误
- material-ui - 如何在自己的 Material-UI 项目中拥有默认的 MuiTheme 文件
- c++ - 验证我对 CMakeLists.txt 文件的理解
- javascript - 在使用 javascript 的不同页面上时,如何在单独的 header.html 中更改活动导航 li?
- reactjs - 在 useEffect 清理函数中取消所有订阅和异步任务
- javascript - 如何在此输入中仅输入数字和减号