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


Groups > comp.lang.python > #64150

Re: extracting string.Template substitution placeholders

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: extracting string.Template substitution placeholders
Date 2014-01-17 09:25 +0000
References <mailman.5370.1389539678.18130.python-list@python.org> <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5630.1389951008.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious 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