csvtxt = '''\ Character,Speech The multitude,The messiah! Show us the messiah! Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away! The multitude,Who are you? Brians mother,I'm his mother; that's who! The multitude,Behold his mother! Behold his mother!\ ''' from cgi import escape def _row2tr(row, attr=None): cols = escape(row).split(',') return ('' + ''.join('%s' % data for data in cols) + '') def csv2html(txt): htmltxt = '\n' for rownum, row in enumerate(txt.split('\n')): htmlrow = _row2tr(row) htmlrow = ' %s\n' % htmlrow htmltxt += htmlrow htmltxt += '
\n' return htmltxt htmltxt = csv2html(csvtxt) print(htmltxt)