[New-bugs-announce] [issue7300] Unicode arguments in str.format()

Walter Dörwald report at bugs.python.org
Tue Nov 10 14:57:35 CET 2009

New submission from Walter Dörwald <walter at livinglogic.de>:

str.format() doesn't handle unicode arguments:

Python 2.6.4 (r264:75706, Oct 27 2009, 15:18:04) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0}'.format(u'\u3042')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u3042' in
position 0: ordinal not in range(128)

Unicode arguments should be treated in the same way as the % operator
does it: by promoting the format string to unicode:

>>> '%s' % u'\u3042'

assignee: eric.smith
components: Interpreter Core
messages: 95114
nosy: doerwalter, eric.smith
severity: normal
status: open
title: Unicode arguments in str.format()
type: behavior
versions: Python 2.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list