Closed nomad-vagabond closed 6 years ago
Hi,
you can use (key, value) pairs for that situation:
with tag('label', ('for', 'whatever')):
...
I think the (key, value) pair is the best solution each time you have to produce an XML attribute name that can't be expressed as a keyword argument in Python. Actually, I only keep the klass
trick to avoid breaking people's code.
Didn't know about (key, value) option. Thanks!
Still, the underscore shielding seems to be more elegant solution from my point of view. If you find it a useful feature I can come out with a pull request. By now I close the issue.
Can we call this out a little better in the tutorial?
Obviously,
class
is not the only reserved word in Python. Some attributes of html elements might have such names asfor
,in
,with
, etc.To deal with all possible conflicts I propose to implement a common solution, based on adding underscore to the names of attributes, which are reserved words in Python.
I personally use
for
attribute in thelabel
tag. Thus, with the proposed improvement I would specify_for
in the definition of the tag, which will be processed by yattag asfor
.