This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse prints help messages to stdout instead of stderr by default
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Alexey Muranov, bethard, serhiy.storchaka
Priority: normal Keywords:

Created on 2016-03-26 12:05 by Alexey Muranov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg262491 - (view) Author: Alexey Muranov (Alexey Muranov) Date: 2016-03-26 12:05
I believe that printing help and usage messages to stdout is a design error.

In stdout i expect to find the output of my program, not help or diagnostic messages.  It is strange to see nothing printed on the screen (where stderr usually goes), and then to find help, usage, or *error* messages in the file where stdout was sent.  (Yes, argparse prints even error messages to stdout by default).

This issue has been discussed before because the implementation did not agree with the documentation: http://bugs.python.org/issue10728
I believe that the conclusion to adjust the documentation to the implementation was a mistake.

P.S. Compare with the direction of the output of `grep -h` or `git -h`.
msg262492 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-26 16:20
`grep --help` outputs to stdout. `grep -h` outputs to stderr, because this is error, there is no the `-h` flag. The same for git and most other command line tools.

argparse follows this behavior. There is no bug.
msg262496 - (view) Author: Alexey Muranov (Alexey Muranov) Date: 2016-03-26 20:32
Thanks for the explanation, this makes sense.  I did not notice that argparse outputs to stderr if command line arguments are wrong, i was probably wrong when said it prints error messages to stdout.  I did not notice indeed that there were no `-h` option in git.

However, my grep version 2.5.1-FreeBSD outputs help to stderr even with `--help` option.
msg262509 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-27 05:25
Does FreeBSD grep support the `--help` option? Long options is GNU extension, classical UNIX commands supported only short options.
msg262512 - (view) Author: Alexey Muranov (Alexey Muranov) Date: 2016-03-27 08:33
My grep man page says

  --help  Print a brief help message.

but indeed there is no `--help` in usage message.  Maybe this is a bug of the man page.

Thanks for the explanation.
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70832
2016-03-27 08:33:18Alexey Muranovsetmessages: + msg262512
2016-03-27 05:25:45serhiy.storchakasetmessages: + msg262509
2016-03-26 20:32:13Alexey Muranovsetmessages: + msg262496
2016-03-26 16:20:04serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg262492

resolution: not a bug
stage: resolved
2016-03-26 12:14:21SilentGhostsetnosy: + bethard

versions: + Python 3.6, - Python 3.5
2016-03-26 12:05:01Alexey Muranovcreate