Jul-24-2018, 07:14 PM
A csv file is text, so can be read like a text file.
But it's better to read as a csv.reader object as each line will be split into a list
to use csv package, you do something like:
But it's better to read as a csv.reader object as each line will be split into a list
to use csv package, you do something like:
import csv def read_file(filename): with open(filename, 'r') as f: reader = csv.reader(f) for row in reader: for col in row: print('{0:<15} '.format(col), end='') print() if __name__ == '__main__': read_file('myfile.csv')if the first row contains headers, you can skip it, or use it for format the data into a dictionary or some other structure.