Project

General

Profile

1
# 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
    dialect.doublequote = True # Sniffer doesn't turn this on by default
12
    header = csv.reader(StringIO.StringIO(header_line), dialect).next()
13
    return (csv.reader(stream, dialect), header)
(3-3/18)