Skip to content

Instantly share code, notes, and snippets.

@danielholmstrom
Created July 13, 2015 16:51
Show Gist options
  • Save danielholmstrom/186fb6bff63039315fee to your computer and use it in GitHub Desktop.
Save danielholmstrom/186fb6bff63039315fee to your computer and use it in GitHub Desktop.
import os
import csv
original_dir = 'first'
new_dir = 'other'
output_dir = 'output'
for (root, dirs, files) in os.walk(original_dir):
for filename in files:
relpath = os.path.join(root, filename)
doc = {}
with open(os.path.join(original_dir, relpath), 'r') as csvfile:
for row in csv.DictReader(csvfile):
doc[row[0]] = row[1]
if os.path.exists(os.path.join(new_dir, relpath)):
with open(os.path.join(new_dir, relpath), 'r') as csvfile:
for row in csv.DictReader(csvfile):
doc[row[0]] = row[1]
# Write
output_path = os.path.join(output_dir, relpath)
print "Would write to", output_path, do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment