A SOLUTION TO THE PROBLEM I POSTED: align_file_rmode = open('/Users/spyros/folder1/python/printsmotifs/alignfiles/' + query1, 'r') align_file_appmode = open('/Users/spyros/folder1/python/printsmotifs/alignfiles/' + query2, 'a+')
finalmotifs = motif_file.readlines() seqalign = align_file_rmode.readlines() for line in seqalign: #align_file_appmode.write('<p> \'line\' </p>') for item in finalmotifs: item = item.strip().upper() annotation = "<span style=\"color:red\">"+item+"</span>" if item in line: newline = line.replace(item, annotation) # sys.stdout.write(newline) align_file_appmode.write(newline) motif_file.close() align_file_rmode.close() align_file_appmode.close() the line annotation = "<span style=\"color:red\">"+item+"</span>" added a span and set the color in CSS. On Tue, May 10, 2011 at 6:14 PM, Spyros Charonis <s.charo...@gmail.com>wrote: > Hi all, > > No need to post answers, I figured out where my mistake was. > > Spyros > > > On Tue, May 10, 2011 at 5:11 PM, Spyros Charonis <s.charo...@gmail.com>wrote: > >> Hello, >> >> I know I posted the exact same topic a few hours ago and I do apologize >> for this, but my script had a careless error, and my real issue is somewhat >> different. >> I have a Python script that extracts some text from a database file and >> annotates another file, writing the results to a new file. Because the >> files I am annotating are ASCII, >> I am very restricted as to how I can annotate the text, and I would like >> to instead write the results to HTML so that I can annotate my file in more >> visually effective ways,e.g. by changing text color where appropriate. My >> program extracts text from a database, reads a file that is to be annotated, >> and writes those >> annotations to a newly created (.htm) file. >> >> finalmotifs = motif_file.readlines() >> seqalign = align_file_rmode.readlines() >> >> # These two files have been created in code that I don't show here because >> it is not relevant to the issue >> >> align_file_appmode.write('<html>') >> align_file_appmode.write('<head>') >> >> align_file_appmode.write >> ('<title> >> \'query_\' Multiple Sequence Alignment >> </title>') >> >> align_file_appmode.write('</head>') >> align_file_appmode.write('<body>') >> >> for line in seqalign: >> align_file_appmode.write('<p> \'line\' </p>') >> for item in finalmotifs: >> item = item.strip().upper() >> if item in line: >> >> newline = line.replace >> (item, '<p> <font color = "red"> \'item\' </font></p>') >> >> align_file_appmode.write(newline) >> >> align_file_appmode.write('</body>') >> align_file_appmode.write('</html>') >> >> motif_file.close() >> align_file_rmode.close() >> align_file_appmode.close() >> >> The .htm file that is created is not what I intend it to be, it has the >> word "item" >> printed every couple lines because I assume I'm not passing the string >> sequence that I want to output correctly. >> >> QUESTION >> Basically, HTML (or the way I wrote my code) does not understand that with >> the >> escape character '\item\' I am trying to print a string and not the word >> "item". >> Is there someway to correct that or would I have to use >> something like XML to create a markup system that specifically describes >> my data? >> >> I am aware Python supports multiline strings (using the format ''' text >> ''') but I do want my HTML ( or XML?) >> to be correctly rendered before I consider making this into a CGI program. >> Built in python 2.6.5 >> > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor