如何使用python调试VSCode上的Google Code Jam交互式问题? [英] How to debug Google Code Jam interactive problems on VSCode using python?

查看:92
本文介绍了如何使用python调试VSCode上的Google Code Jam交互式问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试下载示例交互式问题数字猜测问题.他们在说明"标签中提供了本地测试工具,在分析"标签中提供了python解决方案,并提供了

I tried downloading the example interactive problem number guessing problem. They offer a local testing tool in the Description tab, a python solution in the Analysis tab, a interactive_runner.py that runs both scripts simultaneously.

将解决方案保存在 solution.py 中后,我可以使用以下命令在shell上成功运行它: python3 Interactive_runner.py python3 local_testing_tool.py 0-python3 solution.py .

After saving the solution in a solution.py, I can run this on shell successfully with: python3 interactive_runner.py python3 local_testing_tool.py 0 -- python3 solution.py.

问题是我无法使用VSCode对其进行调试.我尝试将所有3个文件放在一个文件夹中,并使用以下launch.json:

The problem is I can't debug it using VSCode. I tried putting all 3 files in one folder and using the following 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时,出现错误消息:

When I run solutions.py with the debugger I get the error:

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'

有什么更好的方法吗?

推荐答案

程序" 参数仅期望文件的路径,因此出现没有这样的文件或目录"的错误.您要做的就是将其余的执行行用作参数:

The "program" argument expects only the path to a file, hence the error about there being "no such file or directory". What you want to do is take the rest of your execution line and make them arguments:

{
    "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.
        }
    ]
}

这篇关于如何使用python调试VSCode上的Google Code Jam交互式问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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