Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99184 > unrolled thread

Re: String format - resolve placeholders names

Started byErvin Hegedüs <airween@gmail.com>
First post2015-11-20 20:34 +0100
Last post2015-11-20 20:34 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: String format - resolve placeholders names Ervin Hegedüs <airween@gmail.com> - 2015-11-20 20:34 +0100

#99184 — Re: String format - resolve placeholders names

FromErvin Hegedüs <airween@gmail.com>
Date2015-11-20 20:34 +0100
SubjectRe: String format - resolve placeholders names
Message-ID<mailman.19.1448048061.2291.python-list@python.org>
Hi Peter,

On Fri, Nov 20, 2015 at 04:53:47PM +0100, Peter Otten wrote:
> 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)

nice solution, thanks,


a.
 

-- 
I � UTF-8

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web