I have an Excel.CSV file that I am trying to read using DictReader.
Everything seems to be fine, except that it seems to skip rows, especially those that lack columns.
Our entry is as follows:
mail,givenName,sn,lorem,ipsum,dolor,telephoneNumber
ian.bay@blah.com,ian,bay,3424,8403,2535,+65(2)34523534545
mike.gibson@blah.com,mike,gibson,3424,8403,2535,+65(2)34523534545
ross.martin@blah.com,ross,martin,,,,+65(2)34523534545
david.connor@blah.com,david,connor,,,,+65(2)34523534545
chris.call@blah.com,chris,call,3424,8403,2535,+65(2)34523534545
Thus, some of the rows do not have lorem / ipsum / dolor columns, and for them it's just a comma.
We read it with:
def read_gd_dump(input_file="blah 20100423.csv"):
gd_extract = csv.DictReader(open('blah 20100423.csv'), restval='missing', dialect='excel')
return dict([(row['something'], row) for row in gd_extract])
And I checked that "something" (the key for our dict) is not one of the missing columns, I initially suspected that this was possible. This is one of the columns after that.
DictReader, , . restval -, , . , CSV Python (http://docs.python.org/library/csv.html), , , , - .