我不能完全弄清楚發生了什麼事情與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