My program needs to read csv files which may have 1,2 or 3 columns, and it needs to modify its behaviour accordingly. Is there a simple way to check the number of columns withou
I would suggest a simple way like this:
with open('./testfile.csv', 'r') as csv: first_line = csv.readline() your_data = csv.readlines() ncol = first_line.count(',') + 1