def __str__(self):
        """Returns the summary representation as a string."""
        output = self._construct_header()

        if self.print_graph_attributes:
            output.extend(self._construct_graph_attributes())
        if self.print_vertex_attributes:
            output.extend(self._construct_vertex_attributes())

        if self.verbosity <= 0:
            return "\n".join(output)

        if self._graph.ecount() > 0:
            # Add the edge list
            if self.edge_list_format == "auto":
                if (self.print_edge_attributes and self._graph.edge_attributes()):
                    format = "edgelist"
                elif median(self._graph.degree(mode="out")) < 3:
                    format = "compressed"
                else:
                    format = "adjlist"
            else:
                format = self.edge_list_format

            method_name = "_construct_edgelist_%s" % format
            if hasattr(self, method_name):
                output.extend(getattr(self, method_name)())

        if self.wrapper is not None:
            return "\n".join("\n".join(self.wrapper.wrap(line)) for line in output)

        return "\n".join(output)
示例#2
0
    def __str__(self):
        """Returns the summary representation as a string."""
        output = self._construct_header()

        if self.print_graph_attributes:
            output.extend(self._construct_graph_attributes())
        if self.print_vertex_attributes:
            output.extend(self._construct_vertex_attributes())

        if self.verbosity <= 0:
            return "\n".join(output)

        if self._graph.ecount() > 0:
            # Add the edge list
            if self.edge_list_format == "auto":
                if self.print_edge_attributes and self._graph.edge_attributes(
                ):
                    format = "edgelist"
                elif median(self._graph.degree(mode="out")) < 3:
                    format = "compressed"
                else:
                    format = "adjlist"
            else:
                format = self.edge_list_format

            method_name = "_construct_edgelist_%s" % format
            if hasattr(self, method_name):
                output.extend(getattr(self, method_name)())

        if self.wrapper is not None:
            return "\n".join("\n".join(self.wrapper.wrap(line))
                             for line in output)

        return "\n".join(output)