'Python Format Multiline String not working
So I'm trying to generate html files for each day of the year while changing day, month in my template. I've tried the follwing but I get the following error:
Traceback (most recent call last):
File "c:\Users\Galax\Dokumente\Programming\Python\GenerateBirthdayCounters\main.py", line 23, in <module>
make_file(str(month),str(day))
File "c:\Users\Galax\Dokumente\Programming\Python\GenerateBirthdayCounters\main.py", line 9, in make_file
f.write(html.format(day=day.rjust(2, "0"),month=month.rjust(2, "0"),bg="#660066"))
KeyError: '\n --smaller'
This is my main code:
import os
from html import html
os.mkdir("pages")
os.chdir("pages")
def make_file(month, day):
with open(f"{day}.html", "w") as f:
f.write(html.format(day=day.rjust(2, "0"),month=month.rjust(2, "0"),bg="#660066"))
for month in range(1,13):
os.mkdir(str(month))
os.chdir(str(month))
if month == 2:
for day in range(1,29):
make_file(str(month),str(day))
elif month % 2 == 0:
for day in range(1,32):
make_file(str(month),str(day))
else:
for day in range(1,31):
make_file(str(month),str(day))
os.chdir("..")
And this is html.py simplified:
html = """
some text
othertext {month} jsd
text {day} anytest
blabla {bg}
"""
complete file see here (if necessary): https://pastebin.com/pX089Cwc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
