CSDN博客地址

简单的模板替换

html_tmp1 = r"""
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Automation Test Report</title>
    </head>

    <body>
        <div>
            <div class="row">
                <div class="col-11" style="margin-left: 5%%">
                    <label >%(testsetName)s</label>
                </div>
            </div>
        </div>
        
    </body>
</html>
"""

report1 = html_tmp1 % dict(testsetName="中文")

dict(key=value) ⇒ {key: value}
在替换的时候需要将 5%后面多带一个"%“号,否则会报"ValueError: unsupported format character '”’ (0x22) at index 250"错误.

posted @ 2020-03-23 19:58  Yi_warmth  阅读(97)  评论(0编辑  收藏  举报
CSDN博客地址