Skip to content

Instantly share code, notes, and snippets.

@tonyseek
tonyseek / convert_string_template.py
Last active July 11, 2019 17:01
Convert the old style string formatting of Python into the new style one.
import re
def convert_string_template(string):
index = -1
def repl(matched):
nonlocal index
keyword = matched.group(1)
if keyword:
return "{%s}" % keyword.strip('()')