How can I format unicode strings?

Niklas Norrthon niklas.norrthon at hotmail.com
Wed Sep 9 07:24:06 EDT 2009


On 9 Sep, 12:49, gentlestone <tibor.b... at hotmail.com> wrote:
>
> I have python 2.5
>
> return u'{0}'.format(self.name)
>
> doesn't work eigther
>
> the error message i've got is:
>
> 'unicode' object has no attribute 'format'
>
> is the new formatting style newer then python 2.5?

Yes. The new string formatting appeared in python 2.6. Perhaps there
is some __future__ stuff you can import to get it to work, don't know.
If not you are stuck with the old string formatting until you upgrade
to 2.6 or newer:

>>> print u'Hello %s!' % u'world'
Hello world!

/Niklas Norrthon



More information about the Python-list mailing list