Type: Bug
Behaviour
When I use Python: Run Selection/Line in Python Terminal on code that
contains a triple-quoted string with a blank line “sandwiched” between two
non-blank lines, that blank line is removed in the version of the code that
gets executed in the REPL.
Running the same code as a normal script (python file.py) preserves the blank
line. So the behaviour of the code depends on whether it is run as a script or
via Run Selection/Line in Python Terminal, which should not happen.
This breaks code that relies on the exact newline structure of the string, such
as regex-based parsing of multi-line documentation blocks.
Steps to reproduce:
-
Create a new file, e.g. test_blank_line.py, with exactly this content:
text = """line 1
line 2
line 4
"""
print(repr(text))
Note: there is a blank line between line 2 and line 4 inside the
triple-quoted string.
-
Run the file normally in the integrated terminal:
python test_blank_line.py
-
Observe the output:
'line 1\nline 2\n\nline 4\n'
There are two \n characters between line 2 and line 4, as expected.
-
Now select the entire code in test_blank_line.py and run:
- Command Palette → Python: Run Selection/Line in Python Terminal, or
- Right click → Run Selection/Line in Python Terminal.
-
Observe the output printed in the Python REPL in the integrated terminal:
'line 1\nline 2\nline 4\n'
The blank line between line 2 and line 4 is now missing (only a
single \n remains). This shows that the text sent to the REPL by
Run Selection/Line in Python Terminal does not faithfully match the text in
the editor.
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down in the upper-right of the Output panel to Python)
>>> text = """line 1
... line 2
... line 4
... """
>>>
>>> print(repr(text))
'line 1\nline 2\nline 4\n'
>>>
Extension version: 2025.20.1
VS Code version: Code 1.107.1 (994fd12f8d3a5aa16f17d42c041e5809167e845a, 2025-12-17T14:15:14.850Z)
OS version: Windows_NT x64 10.0.26200
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.12
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the
python.languageServer setting: Default
User Settings
languageServer: "Pylance"
Installed Extensions
| Extension Name |
Extension Id |
Version |
| autodocstring |
njp |
0.6.1 |
| cmake-highlight |
zch |
0.0.2 |
| cmake-tools |
ms- |
1.21.36 |
| code-spell-checker |
str |
4.4.0 |
| code-spell-checker-british-english |
str |
1.4.34 |
| code-spell-checker-canadian-english |
str |
1.1.29 |
| copilot-chat |
Git |
0.35.2 |
| cpptools |
ms- |
1.30.0 |
| cpptools-extension-pack |
ms- |
1.3.1 |
| cpptools-themes |
ms- |
2.0.0 |
| debugpy |
ms- |
2025.18.0 |
| graphviz-interactive-preview |
tin |
0.3.5 |
| hexeditor |
ms- |
1.11.1 |
| htmlplay |
bia |
0.0.10 |
| js-debug |
ms- |
1.105.0 |
| js-debug-companion |
ms- |
1.1.3 |
| openscad-language-support |
Lea |
2.0.1 |
| overtype |
DrM |
0.5.0 |
| powershell |
ms- |
2025.4.0 |
| prettier-plus |
Shu |
3.0.0 |
| project-manager |
ale |
13.0.1 |
| python |
ms- |
2025.20.1 |
| remote-containers |
ms- |
0.434.0 |
| text-power-tools |
qcz |
1.51.0 |
| vscode-autohotkey-debug |
zer |
1.11.1 |
| vscode-autohotkey-plus-plus |
mar |
6.7.1 |
| vscode-containers |
ms- |
2.3.0 |
| vscode-js-profile-table |
ms- |
1.0.10 |
| vscode-pylance |
ms- |
2025.10.4 |
| vscode-python-envs |
ms- |
1.14.0 |
| vscode-texttoolbox |
car |
2.29.0 |
System Info
| Item |
Value |
| CPUs |
AMD Ryzen 7 5700U with Radeon Graphics (16 x 1797) |
| GPU Status |
2d_canvas: enabled direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off trees_in_viz: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) |
undefined |
| Memory (System) |
7.38GB (0.77GB free) |
| Process Argv |
--crash-reporter-id 1cf35118-2bd4-4544-b0e1-09535383293d |
| Screen Reader |
yes |
| VM |
0% |
A/B Experiments
vsliv368:30146709
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
6518g693:31436602
aj953862:31281341
nes-set-on:31351930
6abeh943:31336334
envsdeactivate2:31353495
cloudbuttont:31379625
todos-1:31405332
3efgi100_wstrepl:31403338
use-responses-api:31390855
6j29d282:31407606
2a0ce269:31428710
ec5jj548:31422691
terminalsuggestenabled:31431119
cmp-ext-treat:31426748
cp_cls_c_966_ss:31435507
copilot6169-t2000-control:31440805
a9239246:31437220
c0683394:31419495
478ah919:31426797
ge8j1254_inline_auto_hint_haiku:31427726
nes-autoexp-off:31439334
a5gib710:31434435
38bie571_auto:31426784
no_request_with_suggest:31435826
rename_enabled:31436409
7a04d226_do_not_restore_last_panel_session:31438103
anthropic_thinking_t:31432745
p_e9cf0154:31434513
h0hdh950:31428394
cp_cls_c_1081:31433293
copilot-nes-callisto-trt:31434412
nowdiget:31438323
Type: Bug
Behaviour
When I use Python: Run Selection/Line in Python Terminal on code that
contains a triple-quoted string with a blank line “sandwiched” between two
non-blank lines, that blank line is removed in the version of the code that
gets executed in the REPL.
Running the same code as a normal script (
python file.py) preserves the blankline. So the behaviour of the code depends on whether it is run as a script or
via Run Selection/Line in Python Terminal, which should not happen.
This breaks code that relies on the exact newline structure of the string, such
as regex-based parsing of multi-line documentation blocks.
Steps to reproduce:
Create a new file, e.g.
test_blank_line.py, with exactly this content:Note: there is a blank line between
line 2andline 4inside thetriple-quoted string.
Run the file normally in the integrated terminal:
Observe the output:
There are two
\ncharacters betweenline 2andline 4, as expected.Now select the entire code in
test_blank_line.pyand run:Observe the output printed in the Python REPL in the integrated terminal:
The blank line between
line 2andline 4is now missing (only asingle
\nremains). This shows that the text sent to the REPL byRun Selection/Line in Python Terminal does not faithfully match the text in
the editor.
Diagnostic data
Output for
Pythonin theOutputpanel (View→Output, change the drop-down in the upper-right of theOutputpanel toPython)Extension version: 2025.20.1
VS Code version: Code 1.107.1 (994fd12f8d3a5aa16f17d42c041e5809167e845a, 2025-12-17T14:15:14.850Z)
OS version: Windows_NT x64 10.0.26200
Modes:
python.languageServersetting: DefaultUser Settings
Installed Extensions
System Info
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
A/B Experiments