The "loop and a half"

eryk sun eryksun at gmail.com
Sun Oct 8 09:52:49 EDT 2017


On Sun, Oct 8, 2017 at 10:12 AM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
> On Sun, 8 Oct 2017 02:06 am, bartc wrote:
>
>> Especially on
>> Windows where the usual Ctrl C doesn't work, so you resort to Ctrl-Break
>> will which actually abort it. Ctrl Z is uncommon.
>
> Thousands of Python programmers on Windows successfully learned to use Ctrl-Z
> ENTER back in the days of Python 1.5, before quit/exit were added as a
> convenience for beginners, and many of them probably still use it.

Using Ctrl+Z (0x1A) isn't specific to Python. The Windows CRT's
text-mode I/O inherits this from MS-DOS, which took it from CP/M. It's
obvious in Python 2:

    >>> open('test.txt', 'w').write('123\x1a456')
    >>> open('test.txt', 'r').read()
    '123'
    >>> open('test.txt', 'rb').read()
    '123\x1a456'

This has been misreported as a bug more than once.

Python 3 opens CRT file descriptors in binary mode. Its text mode
(TextIOWraper) doesn't implement the legacy Ctrl+Z behavior. However,
Ctrl+Z at the start of a line is manually supported in the REPL and
raw _WindowsConsoleIO.



More information about the Python-list mailing list