In my project I am reading a .csv which has two date values, these are at positions 5 and 14 in the row. The date values can either be null (indicated as '' in the .csv) or they can hold an actual date in the format of mm/dd/yyyy. In order to insert these rows into my geodatabase, I have to convert the '' value to a null, otherwise the value is not recognized as valid for a date field.
I can get the following code to work for each field:
empty = line[5]
if empty == '';
line[5] = None
else:
line[5]=empty
However, I was thinking I could implement a list comprehension to accomplish this more efficiently by using the following:
datelist = [line[5],line[14]]
datelist = [None if date == '' else date for date in datelist]
This doesn't seem to work, I get an error indicating a type mismatch with a date field.
Any thoughts on what I am misunderstanding or how I can approach this. Since I have a working solution its not critical so I am just trying to improve my skills and knowledge a bit here. Though since I am iterating over 20K records, I suppose every bit of efficiency helps.