#! /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()
原文:https://www.cnblogs.com/k8s-pod/p/14729842.html