Created
March 25, 2015 18:52
-
-
Save pdonorio/b55c43b23f9dcf7acc86 to your computer and use it in GitHub Desktop.
Verify CSV header elements against each row of the same file
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
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