Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63959
| Date | 2014-01-14 22:07 -0500 |
|---|---|
| From | "Eric S. Johansson" <esj@harvee.org> |
| Subject | Re: extracting string.Template substitution placeholders |
| References | <mailman.5370.1389539678.18130.python-list@python.org> <52d394ad$0$29874$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5490.1389755274.18130.python-list@python.org> (permalink) |
On 1/13/2014 2:24 AM, Steven D'Aprano wrote:
> On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote:
>
>
> Now just walk the template for $ signs. Watch out for $$ which escapes
> the dollar sign. Here's a baby parser:
found a different way
import string
cmplxstr="""a simple $string a longer $string a $last line"""
nst=string.Template(cmplxstr)
identifiers = {}
while True:
try:
result = nst.substitute(identifiers)
except KeyError, error:
print error
identifiers[error[0]] = "x"
else:
break
print "loop done"
------
at the end I only care about the keys in identifier which I fill in
after user interaction.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
extracting string.Template substitution placeholders "Eric S. Johansson" <esj@harvee.org> - 2014-01-12 10:08 -0500
Re: extracting string.Template substitution placeholders Steven D'Aprano <steve@pearwood.info> - 2014-01-13 07:24 +0000
Re: extracting string.Template substitution placeholders "Eric S. Johansson" <esj@harvee.org> - 2014-01-14 22:07 -0500
Re: extracting string.Template substitution placeholders gmflanagan <cyclebelfast@gmail.com> - 2014-01-16 22:07 -0800
Re: extracting string.Template substitution placeholders Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-17 09:25 +0000
csiph-web