if not hasattr('', 'format'): from string import Template import re def str_format(string, *args, **kwargs): tpl = Template(string) tpl.pattern = str_format.re return tpl.substitute(*args, **kwargs) str_format.re = re.compile(r'\{(?P[A-Za-z0-9_]+)\}') else: def str_format(string, *args, **kwargs): return string.format(*args, **kwargs)