Created
April 7, 2015 19:26
-
-
Save derwolfe/ed4a0344f4eae58f02ac to your computer and use it in GitHub Desktop.
I love python
This file contains 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
import csv | |
def translate_file(fname): | |
translated = [] | |
with open(fname, 'rb') as csvfile: | |
reader = csv.reader(csvfile, delimiter=',') | |
reader.next() | |
for row in reader: | |
translated.append(to_class(row[0], row[1], row[2])) | |
return to_string_list(translated) | |
def to_class(systemid, size, units): | |
return """ | |
new InstrumentUpdates | |
{ | |
SystemId=%s, | |
Size=%s, | |
Units="%s" | |
}""" % (systemid, size, units) | |
def to_string_list(items): | |
return ",".join(items) | |
if __name__ == '__main__': | |
ts = translate_file('./instrument-sizes.csv') | |
with open('instrument-updates.txt', 'w') as f: | |
f.write(ts) | |
print ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment