def read_csv_lines(fname, dialect=None, readahead=16384, **kwargs):
    'A generator of dict records from a CSV/TSV\n\n    Automatically guesses the encoding for each record to convert to UTF-8\n\n    Parameters\n    ----------\n    fname: str\n      Filename\n    dialect: str, optional\n      Dialect to specify to csv.reader. If not specified -- guessed from\n      the file, if fails to guess, "excel-tab" is assumed\n    readahead: int, optional\n      How many bytes to read from the file to guess the type\n    **kwargs\n      Passed to `csv.reader`\n    '
    import csv
    if (dialect is None):
        with open(fname) as tsvfile:
            try:
                dialect = csv.Sniffer().sniff(tsvfile.read(readahead))
            except Exception as exc:
                lgr.warning('Could not determine file-format, assuming TSV: %s', CapturedException(exc))
                dialect = 'excel-tab'
    kw = dict(encoding='utf-8')
    with open(fname, 'r', **kw) as tsvfile:
        csv_reader = csv.reader(tsvfile, dialect=dialect, **kwargs)
        header = None
        for row in csv_reader:
            row_unicode = map(ensure_unicode, row)
            if (header is None):
                header = list(row_unicode)
            else:
                (yield dict(zip(header, row_unicode)))
A generator of dict records from a CSV/TSV

Automatically guesses the encoding for each record to convert to UTF-8

Parameters
----------
fname: str
  Filename
dialect: str, optional
  Dialect to specify to csv.reader. If not specified -- guessed from
  the file, if fails to guess, "excel-tab" is assumed
readahead: int, optional
  How many bytes to read from the file to guess the type
**kwargs
  Passed to `csv.reader`
def read_csv_lines(fname, dialect=None, readahead=16384, **kwargs):
    'A generator of dict records from a CSV/TSV\n\n    Automatically guesses the encoding for each record to convert to UTF-8\n\n    Parameters\n    ----------\n    fname: str\n      Filename\n    dialect: str, optional\n      Dialect to specify to csv.reader. If not specified -- guessed from\n      the file, if fails to guess, "excel-tab" is assumed\n    readahead: int, optional\n      How many bytes to read from the file to guess the type\n    **kwargs\n      Passed to `csv.reader`\n    '
    import csv
    if (dialect is None):
        with open(fname) as tsvfile:
            try:
                dialect = csv.Sniffer().sniff(tsvfile.read(readahead))
            except Exception as exc:
                lgr.warning('Could not determine file-format, assuming TSV: %s', CapturedException(exc))
                dialect = 'excel-tab'
    kw = dict(encoding='utf-8')
    with open(fname, 'r', **kw) as tsvfile:
        csv_reader = csv.reader(tsvfile, dialect=dialect, **kwargs)
        header = None
        for row in csv_reader:
            row_unicode = map(ensure_unicode, row)
            if (header is None):
                header = list(row_unicode)
            else:
                (yield dict(zip(header, row_unicode)))