'How to insert image in HTML in python script?

I am writing a htmlfunction in python as below:

def html(function):
    htmlfile = open(function.name+".html", "w")
    htmlfile.write("<html>\n")
    statement for title
    statement for header
    htmlfile.write ('<img src = '+function.name+'.png alt ="cfg">\n') 
    htmlfile.write("</html>\n")
    htmlfile.close() 

earlier I had files in the same directory where I am running my script. Now I have created a folder images for it and all moved files to this folder. function.name+ pulls up different functions name how to change img src line? when I substitute images/'function.name+', the image doesn't get inserted to HTML.

All images have name in the format

<name of the function>.png 


Solution 1:[1]

Try this. I think this works. The image does get inserted to HTML.

def html(function):
    htmlfile = open(function.name+".html", "w")
    htmlfile.write("<html>\n")
    statement for title
    statement for header
    htmlfile.write('<img src = "' + image_path + '" alt ="cfg">\n')
    htmlfile.write("</html>\n")
    htmlfile.close()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sameera lakshitha