String format - resolve placeholders names
Peter Otten
__peter__ at web.de
Fri Nov 20 10:53:47 EST 2015
Ervin Hegedüs wrote:
> Python has a good string formatter, eg. I can do this:
>
> s = "{who} likes {what}"
> d = {'who': "Adam", 'what': "ants"}
> s.format(**d)
>
> result:
> 'Adam likes ants'
>
> Is it possible, and if yes, how to resolve the placeholders names
> in string?
>>> import string
>>> for item in string.Formatter().parse("{who} likes {what}"):
... print(item)
...
('', 'who', '', None)
(' likes ', 'what', '', None)
More information about the Python-list
mailing list