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.

Author xtreak
Recipients Marcus.Smith, Suzumizaki, dstufft, ncoghlan, paul.moore, tanbro-liu, xtreak
Date 2018-09-23.05:48:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Thanks for the patch. Would you like to make a GitHub PR. I think it's a problem with optparse in general while trying to have a default value with unicode character and %default in the help string. The same code is present in Python 3 but strings are unicode by default. An example code will be below : 

# -*- coding: utf-8 -*-

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
                  help="write to FILE. Default value %default", metavar="FILE", default="早上好")

(options, args) = parser.parse_args()

$ python3.6 ../backups/ --help
Usage: [options]

  -h, --help            show this help message and exit
  -f FILE, --file=FILE  write to FILE. Default value 早上好

$ python2.7 ../backups/ --help
Traceback (most recent call last):
  File "../backups/", line 9, in <module>
    (options, args) = parser.parse_args()
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 1400, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 1440, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 1515, in _process_long_opt
    option.process(opt, value, values, self)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 789, in process
    self.action, self.dest, opt, value, values, parser)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 811, in take_action
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 148: ordinal not in range(128)

Date User Action Args
2018-09-23 05:48:25xtreaksetrecipients: + xtreak, paul.moore, ncoghlan, Suzumizaki, dstufft, Marcus.Smith, tanbro-liu
2018-09-23 05:48:25xtreaksetmessageid: <>
2018-09-23 05:48:25xtreaklinkissue24307 messages
2018-09-23 05:48:24xtreakcreate