def extend(format,d,maker=‘"‘,safe=True):
if safe:
def lookup(w): return d.get(w,w.join(maker*2))
else:
def lookup(w): return d[w]
parts=format.split(maker)
print parts
parts[1::2]=map(lookup, parts[1::2])
print parts
return ‘ ‘.join(parts)
if __name__==‘__main__‘:
print extend(‘just "a" test‘,{‘b‘:‘one‘})
时间: 2024-10-07 09:21:39