why can't % operator use a list?

Andrew Dalke adalke at mindspring.com
Mon May 5 15:32:29 EDT 2003


Peter Hansen:
> 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.

Personally, I nearly always use the () syntax.  After all, in your
example of

>>> someData = 5
>>> print 'value is %s' % someData
value is 5
>>> someData = ['a', 'b']
>>> print 'value is now %s' % someData
value is now ['a', 'b']
>>>

what happens if someData is a tuple?  Rather than worry, I use

>>> print 'value is now %s' % (someData,)

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list