How can I format unicode strings?

Duncan Booth duncan.booth at invalid.invalid
Wed Sep 9 13:29:24 CEST 2009

gentlestone <tibor.beck at> wrote:

> the error message i've got is:
> 'unicode' object has no attribute 'format'
> is the new formatting style newer then python 2.5?
Have you tried reading the documentation? It generally tells you which 
version of Python introduced a feature:

> str.format(format_string, *args, **kwargs)¶
>     Perform a string formatting operation. The format_string argument
>     can contain literal text or replacement fields delimited by braces
>     {}. Each replacement field contains either the numeric index of a
>     positional argument, or the name of a keyword argument. Returns a
>     copy of format_string where each replacement field is replaced
>     with the string value of the corresponding argument. 
>     >>> "The sum of 1 + 2 is {0}".format(1+2)
>     'The sum of 1 + 2 is 3'
>     See Format String Syntax for a description of the various
>     formatting options that can be specified in format strings. 
>     This method of string formatting is the new standard in Python
>     3.0, and should be preferred to the % formatting described in
>     String Formatting Operations in new code. 
>     New in version 2.6.

Duncan Booth

More information about the Python-list mailing list