I have a python file filled with functions like h1 and img and strong for use styling text. Each of these functions are defined as follows:
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)
In an ideal world, to create a div with the class modal, I would call div(content, class="modal") however class is a restricted keyword. Is there any way to bypass this without adding a special case to _createTag?
The PEP 8 standard way of handling that is to add a trailing underscore:
Tkinter.Toplevel(master, class_='ClassName')That’s a common workaround and won’t surprise anyone. You could implement that in your code like:
so that it automatically removes the extra underscore from any and all attributes. Then you could call:
and work around two separate Python namespace conflicts without handling either of them as a special case.