Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99158
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: String format - resolve placeholders names |
| Date | 2015-11-20 16:53 +0100 |
| Organization | None |
| Message-ID | <mailman.3.1448034840.2291.python-list@python.org> (permalink) |
| References | <20151120145227.GB13994@arxnet.hu> |
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)
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: String format - resolve placeholders names Peter Otten <__peter__@web.de> - 2015-11-20 16:53 +0100
Re: String format - resolve placeholders names Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-20 17:08 +0000
Re: String format - resolve placeholders names Ervin Hegedüs <airween@gmail.com> - 2015-11-20 20:36 +0100
csiph-web