striplog/legend.py
def to_csv(self):
        """
        Renders a legend as a CSV string.

        No arguments.

        Returns:
            str: The legend as a CSV.
        """
        # We can't delegate this to Decor because we need to know the superset
        # of all Decor properties. There may be lots of blanks.
        header = []
        component_header = []
        for row in self:
            for j in row.__dict__.keys():
                if j == '_colour':
                    j = 'colour'
                header.append(j)
            for k in row.component.__dict__.keys():
                component_header.append(k)
        header = set(header)
        component_header = set(component_header)
        header.remove('component')
        header_row = ''
        if 'colour' in header:
            header_row += 'colour,'
            header.remove('colour')
            has_colour = True
        for item in header:
            header_row += item + ','
        for item in component_header:
            header_row += 'component ' + item + ','

        # Now we have a header row! Phew.
        # Next we'll go back over the legend and collect everything.
        result = header_row.strip(',') + '\n'
        for row in self:
            if has_colour:
                result += row.__dict__.get('_colour', '') + ','
            for item in header:
                result += str(row.__dict__.get(item, '')) + ','
            for item in component_header:
                result += str(row.component.__dict__.get(item, '')) + ','
            result += '\n'

        return result
def to_csv(self):
        # We can't delegate this to Decor because we need to know the superset
        # of all Decor properties. There may be lots of blanks.
        header = []
        component_header = []
        for row in self:
            for j in row.__dict__.keys():
                if j == '_colour':
                    j = 'colour'
                header.append(j)
            for k in row.component.__dict__.keys():
                component_header.append(k)
        header = set(header)
        component_header = set(component_header)
        header.remove('component')
        header_row = ''
        if 'colour' in header:
            header_row += 'colour,'
            header.remove('colour')
            has_colour = True
        for item in header:
            header_row += item + ','
        for item in component_header:
            header_row += 'component ' + item + ','

        # Now we have a header row! Phew.
        # Next we'll go back over the legend and collect everything.
        result = header_row.strip(',') + '\n'
        for row in self:
            if has_colour:
                result += row.__dict__.get('_colour', '') + ','
            for item in header:
                result += str(row.__dict__.get(item, '')) + ','
            for item in component_header:
                result += str(row.component.__dict__.get(item, '')) + ','
            result += '\n'

        return result
def to_csv ( self ) : # We can't delegate this to Decor because we need to know the superset # of all Decor properties. There may be lots of blanks. header = [ ] component_header = [ ] for row in self : for j in row . __dict__ . keys ( ) : if j == '_colour' : j = 'colour' header . append ( j ) for k in row . component . __dict__ . keys ( ) : component_header . append ( k ) header = set ( header ) component_header = set ( component_header ) header . remove ( 'component' ) header_row = '' if 'colour' in header : header_row += 'colour,' header . remove ( 'colour' ) has_colour = True for item in header : header_row += item + ',' for item in component_header : header_row += 'component ' + item + ',' # Now we have a header row! Phew. # Next we'll go back over the legend and collect everything. result = header_row . strip ( ',' ) + '\n' for row in self : if has_colour : result += row . __dict__ . get ( '_colour' , '' ) + ',' for item in header : result += str ( row . __dict__ . get ( item , '' ) ) + ',' for item in component_header : result += str ( row . component . __dict__ . get ( item , '' ) ) + ',' result += '\n' return result
Renders a legend as a CSV string.

        No arguments.

        Returns:
            str: The legend as a CSV.
Renders a legend as a CSV string .