簡體   English   中英

在 vs 代碼 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執行

另外的選擇:

2.1。 直接在調試控制台中編寫命令。 在當前行的末尾鍵入 {},然后按 shift+enter。 寫完所有行后,回車執行。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM