Why does this (not) work?

Oren Tirosh oren-py-l at hishome.net
Tue Aug 19 17:37:09 EDT 2003


On Tue, Aug 19, 2003 at 05:25:19PM -0400, Michael C. Neel wrote:
> I've got this string in which I need to sub in the same word several
> times; i.e:
> 
> >>> "%s - %s - %s" % ("test","test","test")
> 'test - test - test'
> >>>
> 
> But I want to use the * to make life easier to read, so I tried:
> 
> >>> ("test",)*3
> ('test', 'test', 'test')
> >>> "%s - %s - %s" % ("test",)*3
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: not enough arguments for format string
> >>>

It's just an issie of evaluation order. Try adding parentheses:

>>> "%s - %s - %s" % (("test",)*3)
'test - test - test'

  Oren





More information about the Python-list mailing list