[英]Saving multi-line with variables string to html file
我在python中有函数,它需要几个字符串,应该将它们与应该是html文件的更大字符串连接在一起。
def manzy(product_name, product_image, product_price_new, product_price_before):
a = """ <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<link rel="stylesheet" type="text/css" href="maincss.css">
</head>
<body>
<div class="shop-card">
<div class="title"> """ + product_name + """ </div>
<div class="desc">
Womans cloath
</div>
<div class="slider">
<figure data-color="#E24938, #A30F22 ">
<img src=""" + product_image + """/>
</figure>
</div>
<div class="cta">
<div class="price"> """ + product_price_new + """</div><br>
<div class="price"> """ + product_price_before + """</div>
</div>
</div>
<div class="bg"></div>
</div>
</body>
</html> """
Html_file= open("filename","w")
Html_file.write(a)
Html_file.close()
当我运行代码时,创建了文件,然后出现错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 400: ordinal not in range(128)
我已经读过很少的有关此主题的主题,并且我担心我的错误与将函数参数与此字符串弄乱有关。 但是,该错误并没有说明我弄乱了字符串的格式,也许与此有关?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.