string.Template多用于特定字符串的置换,对替换文件中的内容比较方便,当然前提是指定关键词打好标记
string.Template的替换符号为“$”,和%s类似
常用的操作如下
from string import Template
s='hello,$world!'
t=Template(s)
data = t.substitute({'world':'世界'})
print('hello,世界!'
string.Template多用于特定字符串的置换,对替换文件中的内容比较方便,当然前提是指定关键词打好标记
string.Template的替换符号为“$”,和%s类似
常用的操作如下
from string import Template
s='hello,$world!'
t=Template(s)
data = t.substitute({'world':'世界'})
print('hello,世界!'