Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'subject:skip:s 10': 0.07; 'string': 0.09; '__name__': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'language.': 0.14; 'template': 0.14; "'__main__':": 0.16; 'arg': 0.16; 'identifiers': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'spacing': 0.16; 'utc,': 0.16; 'prevent': 0.16; 'language': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; 'import': 0.22; 'print': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'url:moin': 0.24; 'this:': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'url:wiki': 0.31; 'url:python': 0.33; 'skip:s 30': 0.35; 'in.': 0.36; 'yield': 0.36; 'url:org': 0.36; 'january': 0.37; 'filled': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'above,': 0.60; 'simple': 0.61; 'our': 0.64; 'building,': 0.68; 'received:2': 0.84; 'recognition': 0.84; 'speech': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: extracting string.Template substitution placeholders Date: Fri, 17 Jan 2014 09:25:20 +0000 References: <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-198-27.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389951008 news.xs4all.nl 2838 [2001:888:2000:d::a6]:45918 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64150 On 17/01/2014 06:07, gmflanagan wrote: > On Sunday, January 12, 2014 3:08:31 PM UTC, Eric S. Johansson wrote: >> As part of speech recognition accessibility tools that I'm building, I'm >> >> using string.Template. In order to construct on-the-fly grammar, I need >> >> to know all of the identifiers before the template is filled in. what is >> >> the best way to do this? >> > > Try this: > > import string > cmplxstr="""a simple $string a longer $string a $last line ${another} one""" > > def finditer(s): > for match in string.Template.pattern.finditer(s): > arg = match.group('braced') or match.group('named') > if arg: > yield arg > > > if __name__ == '__main__': > print set(finditer(cmplxstr)) > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence