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


Groups > comp.lang.python > #63959

Re: extracting string.Template substitution placeholders

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <esj@harvee.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'error:': 0.07; 'subject:skip:s 10': 0.07; 'string': 0.09; 'identifier': 0.09; 'try:': 0.09; 'jan': 0.12; 'template': 0.14; '"x"': 0.16; 'escapes': 0.16; 'identifiers': 0.16; 'sign.': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "d'aprano": 0.31; 'keys': 0.31; 'steven': 0.31; 'except': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'break': 0.61; 'simple': 0.61; 'different': 0.65; 'dollar': 0.74; 'walk': 0.74; 'interaction.': 0.84; 'baby': 0.95
X-Virus-Scanned amavisd-new at harvee.org
Date Tue, 14 Jan 2014 22:07:55 -0500
From "Eric S. Johansson" <esj@harvee.org>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.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>
In-Reply-To <52d394ad$0$29874$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5490.1389755274.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389755275 news.xs4all.nl 2852 [2001:888:2000:d::a6]:57666
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63959

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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