I have this following function defined in a file named kwargs.py. (changing the module to unpacking.py made the function work as expected). See the image at the bottom of the question.
def tag(name, *content, cls=None, **attrs):
if cls is not None:
attrs['class'] = cls
if attrs:
attr_str = ''.join(' %s="%s"' % (key,val)
for key, val
in sorted(attrs.items()))
else:
attr_str = ''
if content:
return '\n'.join('<%s%s>%s</%s>' % (name,attr_str,c,name) for c in content)
else:
return '<%s%s />' % (name,attr_str)
when executing this
tag('div', 'testing', cls='test', **dict(id=33,alt='this is a test'))
The result i get is
'<div alt="this is a test" class="test" id="33">testing</div>'
But when i execute this
tag(**dict(name='div', content=('testing','and testing'), cls='test', id=33, alt='this is a test'))
i only get
'<div alt="this is a test" class="test" id="33" />'
why is the parameter name getting assigned but not content. (Even if the tuple is not unpacked i was expecting at least the tuple itself be assigned to content[0]).
What am i missing here?
