Skip to content

Instantly share code, notes, and snippets.

@derwolfe
Created April 7, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derwolfe/ed4a0344f4eae58f02ac to your computer and use it in GitHub Desktop.
Save derwolfe/ed4a0344f4eae58f02ac to your computer and use it in GitHub Desktop.
I love python
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