python / cpython

The Python programming language
https://www.python.org
Other
63.11k stars 30.22k forks source link

print() output garbled if script is double-clicked #109284

Open F7FF opened 1 year ago

F7FF commented 1 year ago

Bug report

Bug description:

See: https://github.com/F7FF/pythonterminalglitch

(Ignore my attempt at linear algebra - the terminal is the problem here)

When I download and double-click this script to run it, the terminal output is mixed up in the wrong order and formatted incorrectly. Changing anything else in the structuring of the script fixes the glitch. This problem does not occur when I run the script from the command line.

Python version info: Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32 (I'm on Windows 11, using an Intel i9-12900H, 32gb of DDR5 DRAM, if it matters)

Untitled

Note that the first 9 lines of output are completely cut off, and 10-15 are smeared across the terminal. Then, 10-19 are written again (properly) and the last two lines are completely cut off again. Resizing the window and scrolling does not fix the issue.

...Is this an issue with print() in the Windows terminal? Sorry for wasting time if this is just my abysmal code.

CPython versions tested on:

3.10

Operating systems tested on:

Windows

matrixbot123 commented 1 year ago

Have you tried running in windows terminal app

zooba commented 1 year ago

I could reproduce output problems (not quite the same) with through double-clicking to py.exe launching a regular Python 3.10 install, but not any Store installs or debug builds. I don't have any other non-Store installs besides 3.10 to try with.

For those testing, add a shebang line to the script (#! python3.x) to choose which version you test with, but it needs to be launched through the Python Launcher. Also check which version of the launcher you have installed (py -h).