splitString output as argument to string format fails?

Peter Otten __peter__ at web.de
Wed Mar 24 13:44:55 EST 2004


U-CDK_CHARLES\Charles wrote:

> But when I attempt something like:
> 
>     f = '%s %s %s' % string.split(eachLine, ',')
> 
> I get:
> 
> TypeError: not enough arguments for format string
> 
> How do I convert the output of string.split into something the format
> operator is happy with?  I'm looking for an "oh well of COURSE" thing,
> rather than looping over the output list and creating a tuple, assuming
> one exists.

The % operator is a bit picky about the sequence type - it wants a tuple:

>>> "%sx%s" % "a,b".split(",")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: not enough arguments for format string


>>> "%sx%s" % tuple("a,b".split(","))
'axb'


Peter



More information about the Python-list mailing list