Skip to content

Instantly share code, notes, and snippets.

@jerm
Created July 3, 2021 23:37
Show Gist options
  • Save jerm/ee25e41606c19e34ca8cb83afb896f1a to your computer and use it in GitHub Desktop.
Save jerm/ee25e41606c19e34ca8cb83afb896f1a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
field_order_fh = open('field_order.txt',"r")
field_order_list = field_order_fh.readlines()
field_order_list_stripped=[]
for f in field_order_list:
field_order_list_stripped.append(f.rstrip('\n'))
with open('my.csv', newline='') as infile:
reader = csv.DictReader(infile)
with open("newfile.csv", 'w+', newline='') as outfile:
writer = csv.DictWriter(outfile, fieldnames=field_order_list_stripped)
writer.writeheader()
for row in reader:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment