from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html'): with tag('head'): with tag('title'): text('Example HTML Page') with tag('body'): with tag('h1'): text('Welcome to my HTML page!') html_str = doc.getvalue() print(html_str)
from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html'): with tag('body'): with tag('ul'): for item in ['apple', 'banana', 'cherry']: with tag('li'): text(item) html_str = doc.getvalue() print(html_str)This code generates an unordered list of three items: "apple", "banana", and "cherry". yattag is a package/library that provides an easy way to generate HTML or XML documents using Python code.