[Tutor] Problem with printing Python output to HTML Correctly

Spyros Charonis s.charonis at gmail.com
Tue May 10 19:14:52 CEST 2011


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.charonis at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110510/80ba6896/attachment-0001.html>


More information about the Tutor mailing list