我不能完全弄清楚发生了什么事情与string templates:Python中的字符串模板:什么是合法字符?
t = Template('cannot teach an ${dog.old} ${tricks.new}. ${why} is this ${not} working')
print t.safe_substitute({'dog.old': 'old dog', 'tricks.new': 'new tricks', 'why': 'OH WHY', 'not': '@#%@#% NOT'})
此打印:
cannot teach an ${dog.old} ${tricks.new}. OH WHY is this @#%@#% NOT working
我认为括号处理任意的字符串。什么字符被允许在大括号,并有任何方式我可以继承Template
做我想要的?
+1:链接文档。 -1:没有真正阅读链接的文档。 – 2010-02-24 15:04:34
WTF?我确实读过它,我对Python和它的文档样式相当陌生(相对于javadoc而言,事情相当冗长)。谢谢你跳过我,因为错过了一个小细节。 – 2010-02-24 15:08:55
所有的编程都是小细节。事实上,你连接到文档都是超过许多关于SO的问题。 – 2010-02-24 15:12:03