# Open the file.with open("C:/programs/file.csv") as f:
# Get dialect from Sniffer.
# ... Pass a sample to sniff.
dialect = csv.Sniffer().sniff(f.read(1024))
# Seek to beginning.
# Read file and print its rows.
r = csv.reader(f, dialect)
for row in r:
print(row)['one', 'two', 'three', '4']
['cat', 'dog', 'mouse', '5']
Discussion. The csv module supports more than is shown on this page. It can also write CSV files. And it provides some features that are superior to using split() such as quote character support.
A summary. A CSV file parser is not always needed. But when complicated features are required, csv.reader and its dialect class are helpful. They make programs easier to develop.