Yeah, I tried this experiment:
from string import Template import uuid class MyTemplate(Template): idpattern = r'[az][_a-z0-9]*(\.[az][_a-z0-9]*)*' t1 = Template('cannot teach an ${dog.old} ${tricks.new}. ${why} is this ${not} working') t2 = MyTemplate('cannot teach an ${dog.old} ${tricks.new}. ${why} is this ${not} working') map1 = {'dog.old': 'old dog', 'tricks.new': 'new tricks', 'why': 'OH WHY', 'not': '@#%@#% NOT'} map2 = {'dog': {'old': 'old dog'}, 'tricks': {'new': 'new tricks'}, 'why': 'OH WHY', 'not': '@#%@#% NOT'} print t1.safe_substitute(map1) print t1.safe_substitute(map2) print t2.safe_substitute(map1) print t2.safe_substitute(map2)
which prints
cannot teach an ${dog.old} ${tricks.new}. OH WHY is this @#%@#% NOT working cannot teach an ${dog.old} ${tricks.new}. OH WHY is this @#%@#% NOT working cannot teach an old dog new tricks. OH WHY is this @#%@#% NOT working cannot teach an ${dog.old} ${tricks.new}. OH WHY is this @#%@#% NOT working
this is how the third one works ( print t2.safe_substitute(map1) ).
source share