Simple formatting string question

Robert Kern kern at caltech.edu
Thu Apr 13 15:34:49 EDT 2000


In article <meh9-637743.14563813042000 at news.cit.cornell.edu>,
	Matthew Hirsch <meh9 at cornell.edu> writes:
> 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.

"""
TypeError: not enough arguments for format string
"""
specifically.

The problem is because of the following behavior:

>>> 6*'%2i' '%1i'
'%2i%1i%2i%1i%2i%1i%2i%1i%2i%1i%2i%1i'

The implicit string concatenation happens before the multiplication.  Add a
+ between the strings first, and the normal order of operations will do what
you want.

GuruQuestion: 
Should implicit string concatenation have a different precedence than
explicit string concatenation?  Perhaps only a mention in
http://www.python.org/doc/current/ref/string-catenation.html ?

> Do you know what the correct syntax should be?
> 
> Thanks,
> Matt

-- 
Robert Kern
kern at caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the Python-list mailing list