why can't % operator use a list?
Peter Hansen
peter at engcorp.com
Mon May 5 12:55:16 EDT 2003
Guy Middleton wrote:
>
> If would be nice if the % operator could work on lists as well as tuples:
>
> >>> print "%s, %s" % ['a', 'b']
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: not enough arguments for format string
> >>> print "%s, %s" % tuple(['a', 'b'])
> a, b
Making that change would make it less nice for users who expect
the current behaviour:
>>> someData = 5
>>> print 'value is %s' % someData
value is 5
>>> someData = ['a', 'b']
>>> print 'value is now %s' % someData
value is now ['a', 'b']
Although it's probably known as a Python wart, in that a single
%s works nicely with whatever is on the right-hand side except
when it's a tuple, it cannot be changed now without breaking a
lot of code, I'm sure.
-Peter
More information about the Python-list
mailing list