reader = csv.reader(f, delimiter=d)
for row in reader:
    row += [None] * (3 - len(row))
try:
    foo, bar, baz = row
except ValueError:
    raise CSVError('Too many columns in input file.')
Find number of columns in csv file