[Python-Dev] converting the stdlib to str.format

Paul Moore p.f.moore at gmail.com
Thu Jun 5 12:50:32 CEST 2008


On 05/06/2008, Steven D'Aprano <steve at pearwood.info> wrote:
> Yes, I don't particularly see the advantage of writing:
>
> "spam %s spam" % (value,)
>
> over
>
> "spam %s spam" % value
>
> Why require the first version?

Because the second breaks if value is a tuple:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> value = (1,2)
>>> "spam %s spam" % value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting

Paul.


More information about the Python-Dev mailing list