'Items in csv format (comma separated).  Use tabs mode for tab
separated.  You can use the .separator command to use a
different one after switching mode.  A separator of comma uses
double quotes for quoting while other separators do not do any
quoting.  The Python csv library used for this only supports
single character separators.'

def output_csv(self, header, line):

    if (sys.version_info < (3, 0)):
        fixdata = (lambda x: x.encode('utf8'))
    else:
        fixdata = (lambda x: x)
    if header:
        if (sys.version_info < (3, 0)):
            import StringIO as io
        else:
            import io
        s = io.StringIO()
        kwargs = {}
        if (self.separator == ','):
            kwargs['dialect'] = 'excel'
        elif (self.separator == ' DCTB '):
            kwargs['dialect'] = 'excel-tab'
        else:
            kwargs['quoting'] = csv.QUOTE_NONE
            kwargs['delimiter'] = fixdata(self.separator)
            kwargs['doublequote'] = False
            kwargs['quotechar'] = '\x00'
        writer = csv.writer(s, **kwargs)
        self._csv = (s, writer)
        if self.header:
            self.output_csv(None, line)
        return
    if (header is None):
        c = self.colour
        line = [((c.header + fixdata(self._fmt_text_col(l))) + c.header_) for l in line]
    else:
        fmt = (lambda x: self.colour.colour_value(x, fixdata(self._fmt_text_col(x))))
        line = [fmt(l) for l in line]
    self._csv[1].writerow(line)
    t = self._csv[0].getvalue()
    if (sys.version_info < (3, 0)):
        t = t.decode('utf8')
    assert t.endswith('\r\n')
    t = t[:(-2)]
    assert ((not t.endswith('\r')) and (not t.endswith('\n')))
    self.write(self.stdout, (t + '\n'))
    self._csv[0].truncate(0)
    self._csv[0].seek(0)
