Skip to content

Instantly share code, notes, and snippets.

@pdonorio
Created March 25, 2015 18:52
Show Gist options
  • Save pdonorio/b55c43b23f9dcf7acc86 to your computer and use it in GitHub Desktop.
Save pdonorio/b55c43b23f9dcf7acc86 to your computer and use it in GitHub Desktop.
Verify CSV header elements against each row of the same file
filecsv = "input.csv"
with open(filecsv, mode='r') as csvfile:
reader = csv.reader(csvfile)
line_count = 0
head = []
data = []
for rows in reader:
if line_count < 1:
head = rows
else:
data = rows
if len(head) != len(data):
print "Fail:\tHeader [" + len(head).__str__()+ "] vs Row " \
+ line_count.__str__() + \
" [" + len(data).__str__() + "]"
print head
print data
exit(1)
line_count += 1
print "No problem found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment