Jump to content

CSV to HTML translation: Difference between revisions

m
tidy up
m (html lang)
m (tidy up)
Line 9:
and returns a text string of an HTML table representing the CSV data. Use the following
data as the CSV text to convert, and show your output.
:Character,SpeachSpeech
:The multitude,The messiah! Show us the messiah!
:Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
Line 23:
===Simple solution===
<lang python>csvtxt = '''\
Character,SpeachSpeech
The multitude,The messiah! Show us the messiah!
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
Line 52:
 
'''Sample (rendered) HTML output'''
 
<lang html><TABLE summary="csv2html program output">
<TBODY><TR><TD>Character</TD><TD>SpeachSpeech</TD></TR></TBODY>
<TBODY><TR><TD>The multitude</TD><TD>The messiah! Show us the messiah!</TD></TR></TBODY>
<TBODY><TR><TD>Brians mother</TD><TD>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</TD></TR></TBODY>
Line 61 ⟶ 60:
<TBODY><TR><TD>The multitude</TD><TD>Behold his mother! Behold his mother!</TD></TR></TBODY>
</TABLE></lang>
 
 
===Extra credit solution===
Line 96 ⟶ 94:
 
'''Sample HTML output'''
<!--
 
(The raw HTML would not render correctly through the wiki interface but shows a suitably coloured table with cell borders).
-->
 
<lang html><TABLE border="1" summary="csv2html extra program output">
<THEAD bgcolor="yellow"><TR><TD>Character</TD><TD>SpeachSpeech</TD></TR></THEAD>
<TBODY bgcolor="orange"><TR><TD>The multitude</TD><TD>The messiah! Show us the messiah!</TD></TR></TBODY>
<TBODY bgcolor="orange"><TR><TD>Brians mother</TD><TD>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</TD></TR></TBODY>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.