Skip to content

Instantly share code, notes, and snippets.

@polymorphm
Last active October 12, 2015 09:47
Show Gist options
  • Save polymorphm/4008428 to your computer and use it in GitHub Desktop.
Save polymorphm/4008428 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8 -*-
assert str is not bytes
import sys
import csv
def main():
for arg in sys.argv[1:]:
csv_path = arg # input CSV-file-path
html_path = arg + '.html' # output HTML-file-path
with open(csv_path, encoding='utf-8', errors='replace') as csv_file, \
open(html_path, 'w', encoding='utf-8', newline='\n') as html_file:
reader = csv.reader(csv_file)
html_file.write('<table>\n{}<tbody>\n'.format(' ' * 2))
for row in reader:
html_file.write('{}<tr>\n'.format(' ' * 4))
for cell in row:
html_file.write('{}<td>{}</td>\n'.format(' ' * 6, cell))
html_file.write('{}</tr>\n'.format(' ' * 4))
html_file.write('{}</tbody>\n</table>\n'.format(' ' * 2))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment