python学习笔记(二十三)-- 参数化替换
def username(): return "testtest" def passwd(): return "123456" #方法字典 fun_map = { "username":username, "password":passwd } s = "<username>,<password>"#需要替换的字符串 for k,func in fun_map.items(): result = func()#把方法名加上()变成可执行 s = s.replace(k,result) print(s)#<testtest>,<123456>