title: How Do I Use Python To Add Images To An HTML File?
body: <p>so I have some images I am attempting to have pop up on an html page when my for loop iterates over a word. Like a hieroglyph translation.</p>
  
  <p>I have gone to my AIs for help but they did not succeed in clearing up my confusion.</p>
  
  <p>Unfortunately, I am unsure on how it is that I write these images into an html page. To clarify, I understand that I need to use the .write() function, but I don't know what HTML to write.</p>
  
  <p>Would it be something like this?</p>
  
  <pre><code>f.write("&lt;html&gt;")
  
  
  f.write("&lt;body&gt;")
  
  
  f.write(&lt;img src=hierpglypha.png, "alt="MyHiero" width="500" height="377"&gt;)
  
  
  f.write("&lt;/body&gt;")
  
  
  f.write("/html&gt;")
  </code></pre>
  
  <p>BREAK</p>
  
  <pre><code>import webbrowser
  
  mydict = {
      'a': 'eglypha.jpg',
      'b': 'eglyphb.jpg',
      'c': 'eglyphc.jpg',
      'd': 'eglyphd.jpg',
      'g': 'eglyph.jpg',
      'h': 'eglyphh.jpg',
      'i': 'eglyphi.jpg',
      'j': 'eglyphj.jpg',
      'k': 'eglyphk.jpg',
      'l': 'eglyphl.jpg',
      'm': 'eglyphm.jpg',
      'n': 'eglyphn.jpg',
      'o': 'eglypho.jpg',
      'p': 'eglypgp.jpg',
      'q': 'eglyphq.jpg',
      'r': 'eglyphr.jpg',
      's': 'eglyphs.jpg',
      't': 'eglypht.jpg',
      'u': 'eglyphu.jpg',
      'v': 'eglyphv.jpg',
      'w': 'eglyphw.jpg',
      'x': 'eglyphx.jpg',
      'y': 'eglyphy.jpg',
      'z': 'eglyphz.jpg',
      '1': 'eglyphTOP.jpg',
      '2': 'eglyphBOTTOM.jpg'
  }
  
  def egypt(x):
      #X is your name.
      myWord = "1"
      s = "" #HTML string to return
      for i in x: #saw this way of writing for loops in a lab. looked pretty nifty, so Im gonna use it
          if(x[i] != 'e' or x[i] != 'f'):
              myWord += x[i]
      myWord += "2"
  
      f.write("&lt;html&gt;")
      f.write("&lt;body&gt;")
  
      for i in myWord:
          f.write("&lt;img src="+ mydict[myWord[i]])
  
  
  
      #TODO
  
  
  
  
  
  
  
  
  
  
  
      return s
  
  #ask user for location of file to be created
  plocation = input("Enter location: ")
  #Create file
  f = open(plocation, 'w')
  
  name = input("Name: ")
  
  #Write the HTML to the file
  f.write(egypt(name))
  
  #Close
  f.close()
  
  #Display it from within Python
  webbrowser.open_new_tab(plocation)
  </code></pre>