Skip to content

Instantly share code, notes, and snippets.

@FinchPowers
Last active August 29, 2015 14:13
Show Gist options
  • Save FinchPowers/f52ec44c37bebc634714 to your computer and use it in GitHub Desktop.
Save FinchPowers/f52ec44c37bebc634714 to your computer and use it in GitHub Desktop.
Why doesn't the second form work?
# ref https://docs.python.org/2/library/string.html#string-formatting
from string import Formatter
class PassThroughFormatter(Formatter):
pass
ptf = PassThroughFormatter()
# works
s = "I am {name} and I am {age} years old"
print ptf.format(s, name="roger", age=12)
#doesn't work
s = "I am {} and I am {} years old"
print ptf.format(s, "roger", 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment