Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Last active December 14, 2015 01:29
Show Gist options
  • Select an option

  • Save bmispelon/5006685 to your computer and use it in GitHub Desktop.

Select an option

Save bmispelon/5006685 to your computer and use it in GitHub Desktop.
Get a list of identifiers in a string.Template()
def get_identifiers(tpl):
identifiers = []
for match in tpl.pattern.finditer(tpl.template):
d = match.groupdict()
identifier = d['named'] or d['braced']
if identifier:
identifiers.append(identifier)
return identifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment