Last active
August 29, 2015 14:13
-
-
Save FinchPowers/f52ec44c37bebc634714 to your computer and use it in GitHub Desktop.
Why doesn't the second form work?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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