blob: ba14fb2aae8bb1acb162fd6ee75cea723d5fc344 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
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<named>[A-Za-z0-9_]+)\}')
else:
def str_format(string, *args, **kwargs):
return string.format(*args, **kwargs)
|