[New-bugs-announce] [issue7649] "u'%c' % char" broken for chars in range '\x80'-'\xFF'

Ezio Melotti report at bugs.python.org
Thu Jan 7 02:08:00 CET 2010

New submission from Ezio Melotti <ezio.melotti at gmail.com>:

On Py2.x u'%c' % char returns the wrong result if char is in range '\x80'-'\xFF':
>>> u'%c' % '\x7f'
u'\x7f'  # correct
>>> u'%c' % '\x80'
u'\uff80'  # broken
>>> u'%c' % '\xFF'
u'\uffff'  # broken

This is what happens whit %s and 0x80:
>>> u'%s' % '\x80'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal
not in range(128)
>>> u'%c' % 0x80

u'%c' % '\x80' should raise the same error raised by u'%s' % '\x80'.

assignee: ezio.melotti
components: Interpreter Core, Unicode
messages: 97334
nosy: ezio.melotti
priority: high
severity: normal
stage: test needed
status: open
title: "u'%c' % char" broken for chars in range '\x80'-'\xFF'
type: behavior
versions: Python 2.6, Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list