Skip to content

Instantly share code, notes, and snippets.

Avatar

Ofer Koren koreno

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