运行 VS 代码中的 loop/multiple 行 python 调试控制台

Running a loop/multiple lines in vs code python debug console

如何在 VS Code 的 python 调试控制台中 运行 一个简单的循环?当我尝试输入以下内容时:

for el in dataset:

它给我以下错误。我似乎可以输入变量名,但不能像在普通 python REPL 中那样输入多行命令。

Traceback (most recent call last):
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 416, in evaluate_expression
    compiled = compile(_expression_to_evaluate(expression), '<string>', 'eval')
  File "<string>", line 1
    for el in dataset:
      ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 969, in internal_evaluate_expression_json
    pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=True)
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 368, in new_func
    return _run_with_unblock_threads(original_func, py_db, curr_thread, frame, expression, is_exec)
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 336, in _run_with_unblock_threads
    return _run_with_interrupt_thread(original_func, py_db, curr_thread, frame, expression, is_exec)
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 307, in _run_with_interrupt_thread
    return original_func(py_db, frame, expression, is_exec)
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 418, in evaluate_expression
    Exec(_expression_to_evaluate(expression), updated_globals, frame.f_locals)
  File "/home/tensorflow/.local/lib/python3.6/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<string>", line 1
    for el in dataset:
                     ^
SyntaxError: unexpected EOF while parsing

您有 2 个选择:

  1. 在新编辑器中编写命令window,然后只需将代码复制并粘贴到调试控制台中,然后按Enter
  2. 直接在调试控制台中编写命令。当您想输入一个新行时,请按 Shift+Enter。命令完成后,执行 Enter