Issue 4297: Add error_log attribute to optparse.OptionParser (original) (raw)

Created on 2008-11-11 14:22 by odd_bloke, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
optparse-error_log.patch odd_bloke,2008-11-11 14:22 Patch adding error_log attribute to OptionParser review
Messages (6)
msg75741 - (view) Author: Daniel Watkins (odd_bloke) * Date: 2008-11-11 14:22
I've recently had to subclass optparse.OptionParser, and copy-paste the exit method, just to change where errors were printed to (I needed stdout rather than stderr). I've also had a request from a client to log errors with command-line parsing to a file, rather than to stdout. So, this patch adds an error_log parameter to OptionParser.__init__ which is used instead of stderr internally (and, of course, defaults to stderr).
msg109574 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-08 19:26
To move this forward would need patches against py3k, assuming that the original patch is agreed upon in principle.
msg109799 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-07-09 21:33
Having an easy way to control where output goes makes sense. This is a new feature, however, and thus only a candidate for 3.2, and in 3.2 it would be better to target it at argparse. I think argarse makes this easier to do via subclassing, but doing so the easy way seems to require overriding a 'private' method (_print_message). I've added Steven to the nosy list to see what he thinks.
msg111301 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-07-23 12:35
Not sure, but I think _print_message in argparse isn't exactly what the OP is looking for if they really only care about errors. If you want to override how errors are printed, then it's absolutely correct to override the error method (in argparse at least), and your overridden method should be given every message that is normally printed as an error. If by errors, you mean "anything the parser might print out" (e.g. the output of "--help"), then you may indeed want _print_message to become public so you can override it. Let me know.
msg128324 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2011-02-10 18:15
Hi Daniel, did you read Steven suggestions? are you willing to propose a patch about your feature request against argparse (optparse is deprecated and no more under development in stdlib)?
msg379658 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-10-26 10:15
Following , argparse now offers a convenient way to handle errors. I propose to close this issue as out of date.
History
Date User Action Args
2022-04-11 14:56:41 admin set github: 48547
2020-11-15 23:48:36 iritkatriel set status: pending -> closedresolution: out of datestage: resolved
2020-10-26 10:15:40 iritkatriel set status: open -> pendingnosy: + iritkatrielmessages: +
2014-02-03 19:17:58 BreamoreBoy set nosy: - BreamoreBoy
2011-02-10 18:15:44 sandro.tosi set nosy: + sandro.tosimessages: +
2010-07-23 12:40:19 eric.araujo set nosy: + eric.araujo
2010-07-23 12:35:27 bethard set messages: +
2010-07-09 21:33:07 r.david.murray set nosy: + r.david.murray, bethardmessages: + versions: - Python 3.1, Python 2.7
2010-07-08 19:26:05 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: + Python 3.1, Python 3.2
2008-11-11 14:35:42 draghuram set nosy: + draghuram
2008-11-11 14:22:58 odd_bloke create