Coverage for e25_xml.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python3
3"""Solution to chapter 6, exercise 25: myxml"""
6def myxml(tagname, content='', **kwargs):
7 """Takes a tag name (string), an optional content string,
8and optional kwargs.
10Returns a string in which "tagname" is an XML tag at the start and end,
11"content" is placed in the middle of the tags, and
12the key-value pairs of kwargs are inserted as attributes in the opening tag.
13"""
14 attrs = ''.join([f' {key}="{value}"'
15 for key, value in kwargs.items()])
16 return f'<{tagname}{attrs}>{content}</{tagname}>'