首页 > 解决方案 > HTML 文件中的 Python 变量

问题描述

我正在尝试将当前月份和当前年份放入 HTML 文件中

#!/usr/local/bin/python3


from datetime import datetime

current_month = datetime.now().strftime('%B')
currentYear = datetime.now().year


html_str="""
<br></br>
<caption><b>Project: </b></caption>Client Projects
<br></br>
<caption><b>Issue Type: </b></caption>Managed Services
<br></br>
<caption><b>Summary: </b></caption>OC SPLA usage report for current_month-currentYear
"""

Html_file= open("1.html","w")
Html_file.write(html_str)
Html_file.close()

但作为输出我得到

OC SPLA usage report for current_month-currentYear

代替

OC SPLA usage report for June-2018

标签: pythonhtml

解决方案


推荐阅读