User Tools

Site Tools

anyfilename = 'textfile001.txt' f = open(anyfilename,'r') output = [] newoutput=[] htmloutput=[] for line in f: if in line: output.append(line) f.close() 'determine length of list and then setnumber_of_lines to this value' count = 0 number_of_lines = 0 linenumber = 0 for i in output: count = count+1 'Now we have the number of lines' number_of_lines = count for i in range(0, number_of_lines): 'print “gubblegub” ' 'print output[i] ' else: print 'Reading the information into output complete now we should perform string operation' print “ ” print “ ” 'First assignment clean output for anything after : in each line' print “Innerloop beginning, finding all instances of ':'” for i in range(0, number_of_lines): search = '</entry>' output[i].find(search) index = output[i].find(search) 'print search, “found at index”, index' 'Now we cut the end of every sentence of output' cut_text_from_string=output[i][13:index] print ' \n' print cut_text_from_string if in line:

  print 'We have now removed all heading text and trailing text after the ":" '
  print "innerloop 2 complete and we can begin stripping down further in order to build our HTML"
  actual_imagefilename - Is the primary variable to find as most of the latter variables will depend upon it, this we 
  read from within the tags <imagename> ??? </imagename> of the line in question, once we have that we are ready to move 
  for i in range(0, number_of_lines):
      search = '<soundname>'
      index = newoutput[i].find(search)
      print search, "found at index", index
      print indexvalue1
      actual_soundfilename = newoutput[i][indexvalue1+11:indexvalue1+11+8]
      print actual_soundfilename
      '''create sentence for soundplayback script'''
      soundplayback = '<embed src="sound/'+actual_soundfilename+'" autostart=false width=0 height=0 name="' + actual_soundfilename[:4] + '" enablejavascript="true">'
      print "This is the soundplayback / embed sentencegeneration" + soundplayback
      '''Use actual_soundfilename to create the_HTML_playbackname_for_an_image '''
      the_HTML_playbackname_for_an_image = actual_soundfilename + '.html'
      print the_HTML_playbackname_for_an_image
      search2 = '</text>'
      index = newoutput[i].find(search2)
      print search2, "found at index", index
      print indexvalue2
      an_alternate_title_for_the_image_for_HTML_purposes = newoutput[i][:indexvalue2]
      print an_alternate_title_for_the_image_for_HTML_purposes
      the_title_of_the_image = an_alternate_title_for_the_image_for_HTML_purposes
      print the_title_of_the_image + 'Is the text displayed on a mouseover'
      search3 = '</imagename>'
      index = newoutput[i].find(search3)
      print search3, "found at index", index
      print indexvalue3
      actual_imagefilename = newoutput[i][indexvalue3-8:indexvalue3]
      print actual_imagefilename
      an_alternate_title_for_the_image_for_HTML_purposes = 'This is the image for ' + an_alternate_title_for_the_image_for_HTML_purposes + ' ' + actual_imagefilename
      print an_alternate_title_for_the_image_for_HTML_purposes
      '''if condition needed for number so that 0 is padded before'''
      generatedHTMLstring = soundplayback + ' <PRE> <UL> <td style="vertical-align: top;"> <center> <img src="images/'+ actual_imagefilename +'" onClick="GetSound(\''+actual_imagefilename[:4]+'\')" img style="border: 0px solid ; width: 70px; height: 60px;" alt="' +an_alternate_title_for_the_image_for_HTML_purposes + ' title="' + the_title_of_the_image + '" src="images/' + actual_imagefilename + '"></center> </PRE> </UL> </td>' 
      print generatedHTMLstring

anyfilename2 = 'htmltablefile001.txt' fob2 = open(anyfilename2,'w') fob2.writelines(htmloutput) fob2.close()

print “Hallo der” 'Open fob for HTML in append mode' 'Write values of our HTML code to fob' 'Close the fob'

' search = '<text>' string.find(search) index = string.find(search) print search, “found at index”, index search2 = '</text>' string.find(search2) index = string.find(search2) print search2, “found at index”, index cut_text_from_string = string[7:24] print cut_text_from_string ' · Last modified: 2012/03/09 10:43 (external edit)