How can I format unicode strings?

Tim Northover T.P.Northover at sms.ed.ac.uk
Wed Sep 9 06:31:08 EDT 2009


gentlestone <tibor.beck at hotmail.com> writes:

>  return u"{}".format(self.name)
>
> this one doesn't work on unicode strings. I there a not old formatting
> style possibilty for unicode strings?

It looks like you're trying to mix python 3.1 and 2.6. In 2.6 you have
to put a number inside the {} to tell it which argument to use. In 3.1
all strings are unicode.

Apparently when 2.7 is released it will backport the empty {} feature
from 3.1. Until then

return u'{0}'.format(self.name)

is what you should probably use.

Tim.



More information about the Python-list mailing list