splitString output as argument to string format fails?

U-CDK_CHARLES\Charles "Charles Krug" at cdksystems.com
Wed Mar 24 14:00:37 EST 2004


On Wed, 24 Mar 2004 19:44:55 +0100, Peter Otten <__peter__ at web.de> wrote:
> 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'

Oh well of COURSE!! :-)

Thanks


Charles




More information about the Python-list mailing list