CSV to HTML translation: Difference between revisions
Content added Content deleted
m (html lang) |
m (tidy up) |
||
Line 9: | Line 9: | ||
and returns a text string of an HTML table representing the CSV data. Use the following |
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. |
data as the CSV text to convert, and show your output. |
||
:Character, |
:Character,Speech |
||
:The multitude,The messiah! Show us the messiah! |
: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> |
:Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
||
Line 23: | Line 23: | ||
===Simple solution=== |
===Simple solution=== |
||
<lang python>csvtxt = '''\ |
<lang python>csvtxt = '''\ |
||
Character, |
Character,Speech |
||
The multitude,The messiah! Show us the messiah! |
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> |
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
||
Line 52: | Line 52: | ||
'''Sample (rendered) HTML output''' |
'''Sample (rendered) HTML output''' |
||
<lang html><TABLE summary="csv2html program output"> |
<lang html><TABLE summary="csv2html program output"> |
||
<TBODY><TR><TD>Character</TD><TD> |
<TBODY><TR><TD>Character</TD><TD>Speech</TD></TR></TBODY> |
||
<TBODY><TR><TD>The multitude</TD><TD>The messiah! Show us the messiah!</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><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></TD></TR></TBODY> |
<TBODY><TR><TD>Brians mother</TD><TD><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></TD></TR></TBODY> |
||
Line 61: | Line 60: | ||
<TBODY><TR><TD>The multitude</TD><TD>Behold his mother! Behold his mother!</TD></TR></TBODY> |
<TBODY><TR><TD>The multitude</TD><TD>Behold his mother! Behold his mother!</TD></TR></TBODY> |
||
</TABLE></lang> |
</TABLE></lang> |
||
===Extra credit solution=== |
===Extra credit solution=== |
||
Line 96: | Line 94: | ||
'''Sample HTML output''' |
'''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"> |
<lang html><TABLE border="1" summary="csv2html extra program output"> |
||
<THEAD bgcolor="yellow"><TR><TD>Character</TD><TD> |
<THEAD bgcolor="yellow"><TR><TD>Character</TD><TD>Speech</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>The multitude</TD><TD>The messiah! Show us the messiah!</TD></TR></TBODY> |
||
<TBODY bgcolor="orange"><TR><TD>Brians mother</TD><TD><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></TD></TR></TBODY> |
<TBODY bgcolor="orange"><TR><TD>Brians mother</TD><TD><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></TD></TR></TBODY> |