[Python-ideas] Shouldn't 'input' prompt be going to stderr?

8 views
Skip to first unread message

MRAB

unread,
Jan 16, 2022, 3:58:06 PMJan 16
to Python-Ideas
There was a discussion on another forum that mentioned the 'input'
function, and it made me wonder whether 'input' should be printing the
prompt to stderr instead of stdout.

The convention is for normal output to go to stdout and error messages
to go to stderr, so if a program needs to ask the user, shouldn't it be
using stderr for prompts in order not to mess up the normal output?
_______________________________________________
Python-ideas mailing list -- python...@python.org
To unsubscribe send an email to python-id...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python...@python.org/message/DPWGFP2E77QSNRXQGSULIVIXA5QC7NFL/
Code of Conduct: http://python.org/psf/codeofconduct/

Cameron Simpson

unread,
Jan 16, 2022, 10:11:57 PMJan 16
to Python-Ideas
On 16Jan2022 20:57, MRAB <pyt...@mrabarnett.plus.com> wrote:
>There was a discussion on another forum that mentioned the 'input'
>function, and it made me wonder whether 'input' should be printing the
>prompt to stderr instead of stdout.
>
>The convention is for normal output to go to stdout and error messages
>to go to stderr, so if a program needs to ask the user, shouldn't it be
>using stderr for prompts in order not to mess up the normal output?

This is a good reason to avoid sending prompts to stdout. But stderr
isn't necessarily right either. If stderr's attached to a tty (UNIX,
different techiness for Windows) you could reasonably send to stderr,
otherwise you might be better opening /dev/tty (if you're allowed to,
and if you have one). Etc etc.

There was a long thread in the "Core Development" forum just the other
day about this, here:
https://discuss.python.org/t/builtin-function-input-writes-its-prompt-to-sys-stderr-and-not-to-sys-stdout/12955

Have a read.

Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
Python-ideas mailing list -- python...@python.org
To unsubscribe send an email to python-id...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python...@python.org/message/NNK7KBEAOIHKHZVXLMDRAHQOIYYP6FSC/

MRAB

unread,
Jan 16, 2022, 10:56:12 PMJan 16
to python...@python.org
On 2022-01-17 03:11, Cameron Simpson wrote:
> On 16Jan2022 20:57, MRAB <pyt...@mrabarnett.plus.com> wrote:
>>There was a discussion on another forum that mentioned the 'input'
>>function, and it made me wonder whether 'input' should be printing the
>>prompt to stderr instead of stdout.
>>
>>The convention is for normal output to go to stdout and error messages
>>to go to stderr, so if a program needs to ask the user, shouldn't it be
>>using stderr for prompts in order not to mess up the normal output?
>
> This is a good reason to avoid sending prompts to stdout. But stderr
> isn't necessarily right either. If stderr's attached to a tty (UNIX,
> different techiness for Windows) you could reasonably send to stderr,
> otherwise you might be better opening /dev/tty (if you're allowed to,
> and if you have one). Etc etc.
>
> There was a long thread in the "Core Development" forum just the other
> day about this, here:
> https://discuss.python.org/t/builtin-function-input-writes-its-prompt-to-sys-stderr-and-not-to-sys-stdout/12955
>
> Have a read.
>
Thanks for that.

I did think that it's way too late to change it now, but perhaps an
argument to redirect the prompt is a possibility.
_______________________________________________
Python-ideas mailing list -- python...@python.org
To unsubscribe send an email to python-id...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python...@python.org/message/N2AUBLP2U46LJOQA7P5G62VAMOGL2H2I/
Reply all
Reply to author
Forward
0 new messages