简体   繁体   English

在 vs 代码 python 调试控制台中运行循环/多行

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

How do I run a simple loop in VS Code's python debug console?如何在 VS Code 的 python 调试控制台中运行一个简单的循环? When I try to enter the following:当我尝试输入以下内容时:

for el in dataset:

It gives me the error below.它给了我下面的错误。 I seem to be able to enter variable names, but not multi-line commands like I can in the normal python REPL.我似乎能够输入变量名,但不能像在普通 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

You have 2 options:您有 2 个选项:

  1. Write the command in a new editor window, then simply copy and paste the code in the debug console and press Enter在新编辑器 window 中编写命令,然后只需将代码复制并粘贴到调试控制台中,然后按Enter
  2. Write the command directly in the debug console.直接在调试控制台中编写命令。 When you want to enter a new line, press Shift+Enter .如果要输入新行,请按Shift+Enter When the command is complete, execute with Enter命令完成后, Enter执行

Another option:另外的选择:

2.1. 2.1。 Write the command directly in the debug console.直接在调试控制台中编写命令。 Type {} at the end of current line, then press shift+enter.在当前行的末尾键入 {},然后按 shift+enter。 After complete writing all lines, press enter to execute.写完所有行后,回车执行。

 for i in [1,2,3]: {'''press shift+enter here'''} for i in [1,2,3]: { print(i) #press enter here }

Reference https://youtu.be/p8zMXKFlkqk?t=50参考https://youtu.be/p8zMXKFlkqk?t=50

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM