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.ArgumentParser.print_help uses sys.stdout
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: bethard, docs@python, eric.araujo, jgehrcke, r.david.murray, silvioricardoc
Priority: normal Keywords:

Created on 2010-12-18 03:10 by silvioricardoc, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg124271 - (view) Author: Silvio Ricardo Cordeiro (silvioricardoc) Date: 2010-12-18 03:10
The documentation at http://docs.python.org/dev/library/argparse.html explicitly says that "If file is None, sys.stderr is assumed".

However, both print_usage and print_help assume sys.stdout when file=None. The helper method _print_message actually does it right, when called with file=None.
msg124273 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-18 04:09
I think this is a documentation bug, since IMO help should print on stdout, not stderr[1].  I would expect print_usage to do likewise, but for the error to tell print_usage to write to stderr when it calls it...which is exactly what the code does.

[1] I know some unix commands print help to stderr, and this really annoys me when I pipe long help output to less....and it *still* scrolls off the screen.
msg124279 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-12-18 10:41
Yep, this is a documentation bug. Help is definitely intended to print to stdout.
msg124289 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-18 16:40
Fixed in r87372.
msg124368 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-19 23:35
This apparently lacks a 2.7 backport.
msg124379 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-20 01:24
Like Georg, I'll get to that when I do a mass backport of all my doc fixes.  My apologies for missing the beta2 deadline on doing that, but there aren't many of them.
msg124400 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-20 19:25
Alright, I didn’t know you were doing mass merges.  I personally prefer to leave reports open until backported, now I’ll know your habits.
msg211217 - (view) Author: Dr. Jan-Philip Gehrcke (jgehrcke) * Date: 2014-02-14 12:25
The version action currently writes to stderr. The _VersionAction(Action)'s __call__() method finishes off with 

parser.exit(message=formatter.format_help())

and parser.exit() by default writes to stderr.

Here, Steven says "Help is definitely intended to print to stdout." and I expected the same to happen regarding the version information. Why should it go to stderr?

I see that this is a minor problem and only if someone here agrees I would open an issue for that.
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 54937
2014-02-14 12:25:01jgehrckesetnosy: + jgehrcke
messages: + msg211217
2010-12-20 19:25:04eric.araujosetnosy: bethard, eric.araujo, r.david.murray, docs@python, silvioricardoc
messages: + msg124400
2010-12-20 01:24:44r.david.murraysetnosy: bethard, eric.araujo, r.david.murray, docs@python, silvioricardoc
messages: + msg124379
2010-12-19 23:35:50eric.araujosetnosy: + eric.araujo
messages: + msg124368
2010-12-18 16:40:09r.david.murraysetstatus: open -> closed
nosy: bethard, r.david.murray, docs@python, silvioricardoc
messages: + msg124289

resolution: fixed
stage: needs patch -> resolved
2010-12-18 10:41:38bethardsetnosy: bethard, r.david.murray, docs@python, silvioricardoc
messages: + msg124279
versions: - Python 3.1
2010-12-18 04:09:55r.david.murraysetnosy: bethard, r.david.murray, docs@python, silvioricardoc
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2010-12-18 04:09:25r.david.murraysetnosy: + docs@python, r.david.murray, bethard
messages: + msg124273

assignee: docs@python
components: + Documentation, - Library (Lib)
stage: needs patch
2010-12-18 03:10:54silvioricardoccreate