Created
September 8, 2015 14:33
-
-
Save ejmurray/62450101b2c89a39925f to your computer and use it in GitHub Desktop.
Convert the referece data to a html output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
__author__ = 'Ernest Murray' | |
__Created__: 08/09/2015 | |
This script takes the content of a file, in this case a tab separated file and | |
converts it to an html table. The headers for html file are contained in the text file. | |
The output is given in the sys.out field. | |
# https://goo.gl/Hn1nzf | |
# https://goo.gl/ZY5JYJ | |
""" | |
# TODO(EM): direct the output to a html file | |
import csv | |
from prettytable import PrettyTable | |
with open("data.txt", "r") as fp: | |
reader = csv.DictReader(fp, dialect='excel-tab') | |
ptable = PrettyTable(reader.fieldnames) | |
for rowdict in reader: | |
ptable.add_row([rowdict[fn] for fn in reader.fieldnames]) | |
print ptable.get_html_string() | |
fp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment