(self, header, line)
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.
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.
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):
        """
        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.
        """

        # we use self._csv for the work, setup when header is
        # supplied. _csv is a tuple of a StringIO and the csv.writer
        # instance.

        # Sigh
        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 == "\t":
                kwargs["dialect"] = "excel-tab"
            else:
                kwargs["quoting"] = csv.QUOTE_NONE
                kwargs["delimiter"] = fixdata(self.separator)
                kwargs["doublequote"] = False
                # csv module is bug ridden junk - I already say no
                # quoting so it still looks for the quotechar and then
                # gets upset that it can't be quoted.  Which bit of no
                # quoting was ambiguous?
                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")
        # csv lib always does DOS eol
        assert (t.endswith("\r\n"))
        t = t[:-2]
        # should not be other eol irregularities
        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)
def output_csv ( self , header , line ) : # we use self._csv for the work, setup when header is # supplied. _csv is a tuple of a StringIO and the csv.writer # instance. # Sigh 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 == "\t" : kwargs [ "dialect" ] = "excel-tab" else : kwargs [ "quoting" ] = csv . QUOTE_NONE kwargs [ "delimiter" ] = fixdata ( self . separator ) kwargs [ "doublequote" ] = False # csv module is bug ridden junk - I already say no # quoting so it still looks for the quotechar and then # gets upset that it can't be quoted.  Which bit of no # quoting was ambiguous? 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" ) # csv lib always does DOS eol assert ( t . endswith ( "\r\n" ) ) t = t [ : - 2 ] # should not be other eol irregularities 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 )