Problem with string format

Terry Reedy tjreedy at udel.edu
Wed Mar 11 18:16:26 CET 2009


Mike314 wrote:
> Hello,
> 
>    I have a strange problem with the string format:
> 
>>>> '%s %s %s %s %s' % ['01', '02', '03', '04', '05']
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: not enough arguments for format string
> 
> But as soon I use tuple it is working:
>>>> '%s %s %s %s %s' % ('01', '02', '03', '04', '05')
> '01 02 03 04 05'
> 
> 
> What is the problem and how can I still use list?

This sort of confusion between object as object and object as container 
of objects was one of the reasons for the development of the new 
str.format function.  Within a call, [1,2,3] is one argument matching 
one field.  *[1,2,3], for instance, becomes three arguments matching 
three fields.




More information about the Python-list mailing list