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
Milister
  • 648
  • 1
  • 15
  • 33
  • @Tomalak, i tried it already before posting question here – Milister Jun 06 '18 at 09:43
  • The answers in the duplicate question show *exactly* what you need to do. Also, your question does not indicate that you have tried. – Tomalak Jun 06 '18 at 09:51
  • 1
    sorrym, i made a typo when trying it-it works now, thank You – Milister Jun 06 '18 at 10:02
  • 'Summary: OC SPLA usage report for {current_month}-{currentYear} """.format(**locals())' works, thanks @Tomalak for pointing me to right link – Milister Jun 06 '18 at 10:03
  • Good to hear you figured it out after all! – Tomalak Jun 06 '18 at 10:04
  • I'm not a developer, that's why i had issues to grasp it at first – Milister Jun 06 '18 at 10:04
  • 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. – Tomalak Jun 06 '18 at 10:10

0 Answers0