Simple formatting string question

Sean Blakey sblakey at freei.com
Thu Apr 13 21:06:37 CEST 2000


On 13 Apr, Matthew Hirsch wrote:
> Hi All,
> 
> I'm trying to print something like this:
> 
>>>> print 6*'%2i' '%1i' % tuple([5,5,5,5,5,5,1])
> 
> but I'm getting an error.
> 
> Do you know what the correct syntax should be?
> 
> Thanks,
> Matt
Two issues:
First, you have to concatenate the format stings with plus.
Second, formating binds more tightly than string formatting, so you
will need parentheses around "6x'%2i' + '%1i'".

What I got to work was:
>>> print (6*'%2i' + '%1i') % tuple([5,5,5,5,5,5,1])
 5 5 5 5 5 51

-- 

Sean Blakey
FreeInternet.com
sblakey at freei.com
(253)796-6500x1025





More information about the Python-list mailing list