7,python3 生成Html文件

#! /usr/bin/python3
# coding:utf-8

# 设置生成文件的文件名
# 设置编码 encoding="utf-8" ,不然可能会出现乱码的情况
file_name = "test.html"


# 打开文件,准备写入
f = open(file_name, 'w', encoding="utf-8")

title = '我是标题'
content = '我是内容'

msg = """<html>
	<head>
		<title>%s</title>
	</head>
	
	<body>
		<p>%s</p>  
	</body>
</html>"""	%(title, content)



# 写入文件
f.write(msg)
# 关闭文件
f.close()

 

posted @ 2021-05-04 17:08  pwcc  阅读(432)  评论(0)    收藏  举报