Project

General

Profile

1 1388 aaronmk
# CSV I/O
2
3
import csv
4
import StringIO
5
6
def reader_and_header(stream):
7
    '''Automatically detects the dialect based on the header line
8
    @return tuple (reader, header)'''
9
    header_line = stream.readline()
10
    dialect = csv.Sniffer().sniff(header_line)
11
    header = csv.reader(StringIO.StringIO(header_line), dialect).next()
12
    return (csv.reader(stream, dialect), header)