Created
July 3, 2021 23:37
-
-
Save jerm/ee25e41606c19e34ca8cb83afb896f1a to your computer and use it in GitHub Desktop.
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
#!/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