1

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 
   
7
  • htmlfile.write ('<img src = "'+function.name+'.png" alt ="cfg">\n') Commented Jul 2, 2015 at 21:08
  • Looks like you forgot quotes around the src attribute. Commented Jul 2, 2015 at 21:08
  • Try: '<img src = "{}.png" alt = "cfg">\n'.format(function.name) Commented Jul 2, 2015 at 21:10
  • @heinst : thanks for correction. Basically when I run my script png file gets generated and i insert it to html. earlier it used to be in the same directory as script run directory. now i have created a folder to keep all png files and trying to call it from that folder. I am writing images/+function.name+.png, but it doesn't show image on html page Commented Jul 2, 2015 at 21:16
  • 1
    @geek_xed try htmlfile.write('<img src = "' + image_path + '" alt ="cfg">\n') Commented Jul 2, 2015 at 21:42

2 Answers 2

2

You can implement it as below:

from robot.api import logger

img = "example.jpg"
strImg = '"{}"'.format(img)

img_tag = "<img src=" + strImg + ">"
logger.info(img_tag, html=True)
Sign up to request clarification or add additional context in comments.

Comments

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.