How can I format unicode strings?

gentlestone tibor.beck at hotmail.com
Wed Sep 9 06:49:42 EDT 2009


On 9. Sep., 12:31 h., Tim Northover <T.P.Northo... at sms.ed.ac.uk>
wrote:
> gentlestone <tibor.b... 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.

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?




More information about the Python-list mailing list