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)) -- https://mail.python.org/mailman/listinfo/python-list