Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FIOC IS BROKEN

Name: Anonymous 2012-12-13 10:56

>>> 'string with no string formatting markers' % ['string']
'string with no string formatting markers'
>>> 'string with no string formatting markers' % ('string',)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting

FIOC IS BROKEN!

Name: Anonymous 2012-12-13 11:16

This is kind of misleading, though:

>>> '%s and %s' % ['a', 'b']

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    '%s and %s' % ['a', 'b']
TypeError: not enough arguments for format string


Lists are a single argument to %, so they logically behave differently from tuples here. The point you really want to make is a % b not being equivalent to a % (b,).

Which is still broken, I guess. The lesson here is you shouldn't ever be using % on strings anymore; there's format for that now, and it's much more readable (and Pythonic!)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List