使用pythonic语法将html写入类似文件的对象。
htmlwrite的Python项目详细描述
htmlwrite是一个python库,用于使用pythonic语法将html写入类似文件的对象。用作模板引擎的替代品。
>>> import sys >>> >>> from htmlwrite import Writer, Tag >>> >>> writer = Writer(sys.stdout) >>> w = writer.write >>> c = writer.context >>> >>> with c(Tag('html')): ... with c(Tag('body')): ... with c(Tag('div', class_=('foo', ), s_font_weight='bold')): ... w('Hello world ') ... w(Tag('div'), 'ok, bye.') ... <html> <body> <div class="foo" style="font-weight: bold;"> Hello world </div> <div>ok, bye.</div> </body> </html>