Problem with string format

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Mar 11 06:17:38 CET 2009


On Tue, 10 Mar 2009 22:07:59 -0700, 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?

There is no problem and you can't. As far as string formatting is 
concerned, a list is a single object which goes into a single %s.


Try converting the list into a tuple first:

'%s %s %s %s %s' % tuple(['01', '02', '03', '04', '05'])



-- 
Steven



More information about the Python-list mailing list