0

I'm trying to put current month and current year into HTML file

#!/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()

But as output i'm getting

OC SPLA usage report for current_month-currentYear

Instead of

OC SPLA usage report for June-2018
7
  • @Tomalak, i tried it already before posting question here Commented Jun 6, 2018 at 9:43
  • The answers in the duplicate question show exactly what you need to do. Also, your question does not indicate that you have tried. Commented Jun 6, 2018 at 9:51
  • 1
    sorrym, i made a typo when trying it-it works now, thank You Commented Jun 6, 2018 at 10:02
  • '<caption><b>Summary: </b></caption>OC SPLA usage report for {current_month}-{currentYear} """.format(**locals())' works, thanks @Tomalak for pointing me to right link Commented Jun 6, 2018 at 10:03
  • 1
    No problem at all. For reference, the act of getting variable values into a string is called "interpolation". Different languages have different syntax, but most can do it one way or the other. Using f'{current_month}' (note the f in front of the string) is another way that works in Python. Commented Jun 6, 2018 at 10:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.