The little csv module that could
Monday, 2 April 2007
The CSV module in python can process more than just CSV files. It can also handle tab separated ones.
In fact, it has an in-built sniffer to guess what type of delimiters the file is using. This includes guessing whether strings are quoted or not.
Here’s some sample code:
dialect=csv.Sniffer().sniff(open('fitted.txt', 'r').read())
for column_1, column_2, column_3 in \
csv.reader(open('fitted.txt', 'r'), dialect=dialect):
pass # do something here
No. 1 — April 8th, 2007 at 2:15 pm
Python CSV module has a delimiter sniffer…
According to Chui , Python’s built-in CSV module has a delimiter sniffer . I did not know this, but I can probably make good use of it at work. I’ll have to play with it….