def str_format(string, *args, **kwargs): tpl = Template(string) tpl.pattern = str_format.re return tpl.substitute(*args, **kwargs)