[ python-Bugs-1498146 ] optparse does not hande unicode help strings (original) (raw)
Bugs item #1498146, was opened at 2006-05-31 07:52 Message generated for change (Comment added) made by gward You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1498146&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Unicode Group: Python 2.4
Status: Closed Resolution: Fixed Priority: 5 Submitted By: Tom Cato Amundsen (tomcato) Assigned to: Greg Ward (gward) Summary: optparse does not hande unicode help strings
Initial Comment: Unicode strings with non-ascii chars in generate a UnicodeEncodeError
File "/usr/lib/python2.3/optparse.py", line 1370, in print_help file.write(self.format_help()) UnicodeEncodeError: 'ascii' codec can't encode characters in position 200-202: +ordinal not in range(128)
I'm subclassing OptionParser and adds the following method to get it to work. Should something like this be done for python 2.5?
def print_help(self, file=None): if file is None: file = sys.stdout file.write(self.format_help().encode(file.encoding, 'replace'))
Tom Cato
Comment By: Greg Ward (gward) Date: 2006-06-11 12:25
Message: Logged In: YES user_id=14422
Fixed pretty much as suggested in upstream Optik repository: r520.
(However, I had to use getattr(file, 'encoding', sys.getdefaultencoding()) to maintain compatibility with Python 2.0 .. 2.2).
No doc changes, since help generation isn't really documented all that well anywhere. ;-(
Fixed on Python trunk: r46861.
You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1498146&group_id=5470
Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com