from string import Template
def simple_format(text, *args):
class T(Template):
delimiter = '%'
idpattern = '\d+'
return T(text).safe_substitute({str(i):v for i, v in enumerate(args)})
simple_format("%1 calls %0 and %2", "ashok", "hari")
# hari calls ashok and %2
如果您确实需要函数
^{pr2}$simple_format
,那么:示例:
下面是一个使用
string.Template
的示例:更新:
相关问题 更多 >
编程相关推荐