I'm trying to create an HTML file, which certains Python variables that have to be evaluated. My code looks like this:
name = ['Nora', 'John', 'Jack', 'Jessica']
html = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Names</title>
</head>
<body>
<ul>
<li>Mother: <%= name[0] %></li>
<li>Father: <%= name[1] %></li>
<li>Son: <%= name[2] %></li>
<li>Daughter: <%= name[3] %></li>
</ul>
</body>
</html>
"""
Html_file = open("names.html","w")
Html_file.write(html)
Html_file.close()
However, the array is not interpreted during output. My HTML source looks like this:
...
<ul>
<li>Mother: <%= name[0] %></li>
<li>Father: <%= name[1] %></li>
<li>Son: <%= name[2] %></li>
<li>Daughter: <%= name[3] %></li>
</ul>
...
How can I evaluate the python code that's surrounded by <%= %>
?