我有一個Python文件,其中填充了h1
和img
和strong
之類的函數以供使用樣式文本。這些函數的定義如下:允許使用令牌`類`作爲方法簽名中的命名參數
def _wrapTag(tag, text, **attributes):
out = _createTag(tag, **attributes)
out += text
out += "</" + tag + ">"
return out
def _createTag(tag, **attributes):
out = "<" + tag
if attributes:
for attr, value in attributes:
out += " " + attr + "=\"" + value + "\""
out += ">"
return out
def h2(text, **attributes):
return _wrapTag("h2", text, **attributes)
在一個理想的世界,創造與類modal
一個div
,我會打電話div(content, class="modal")
然而class
是受限制的關鍵字。有沒有什麼辦法可以繞過這個而不需要在_createTag
增加一個特殊情況?
呃,我的感覺可能是真的。不管怎樣,謝謝你。 – Drakekin