Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? 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.

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
like image 959
xdhmoore Avatar asked Jun 10 '26 19:06

xdhmoore


1 Answers

You have 2 options:

  1. Write the command in a new editor window, then simply copy and paste the code in the debug console and press Enter
  2. Write the command directly in the debug console. When you want to enter a new line, press Shift+Enter. When the command is complete, execute with Enter
like image 60
GZZ Avatar answered Jun 13 '26 08:06

GZZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!