def write(G, weighted=False):
dotG = pydot.Dot()<EOL>if not '<STR_LIT:name>' in dir(G):<EOL><INDENT>dotG.set_name('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>dotG.set_name(G.name)<EOL><DEDENT>if (isinstance(G, graph)):<EOL><INDENT>dotG.set_type('<STR_LIT>')<EOL>directed = False<EOL><DEDENT>elif (isinstance(G, digraph)):<EOL><INDENT>dotG.set_type('<STR_LIT>')<EOL>directed = True<EOL><DEDENT>elif (isinstance(G, hypergraph)):<EOL><INDENT>return write_hypergraph(G)<EOL><DEDENT>else:<EOL><INDENT>raise InvalidGraphType("<STR_LIT>" %  repr(G) )<EOL><DEDENT>for node in G.nodes():<EOL><INDENT>attr_list = {}<EOL>for attr in G.node_attributes(node):<EOL><INDENT>attr_list[str(attr[<NUM_LIT:0>])] = str(attr[<NUM_LIT:1>])<EOL><DEDENT>newNode = pydot.Node(str(node), **attr_list)<EOL>dotG.add_node(newNode)<EOL><DEDENT>seen_edges = set([])<EOL>for edge_from, edge_to in G.edges():<EOL><INDENT>if (str(edge_from) + "<STR_LIT:->" + str(edge_to)) in seen_edges:<EOL><INDENT>continue<EOL><DEDENT>if (not directed) and (str(edge_to) + "<STR_LIT:->" + str(edge_from)) in seen_edges:<EOL><INDENT>continue<EOL><DEDENT>attr_list = {}<EOL>for attr in G.edge_attributes((edge_from, edge_to)):<EOL><INDENT>attr_list[str(attr[<NUM_LIT:0>])] = str(attr[<NUM_LIT:1>])<EOL><DEDENT>if str(G.edge_label((edge_from, edge_to))):<EOL><INDENT>attr_list['<STR_LIT:label>'] = str(G.edge_label((edge_from, edge_to)))<EOL><DEDENT>elif weighted:<EOL><INDENT>attr_list['<STR_LIT:label>'] = str(G.edge_weight((edge_from, edge_to)))<EOL><DEDENT>if weighted:<EOL><INDENT>attr_list['<STR_LIT>'] = str(G.edge_weight((edge_from, edge_to)))<EOL><DEDENT>newEdge = pydot.Edge(str(edge_from), str(edge_to), **attr_list)<EOL>dotG.add_edge(newEdge)<EOL>seen_edges.add(str(edge_from) + "<STR_LIT:->" + str(edge_to))<EOL><DEDENT>return dotG.to_string()<EOL>
Return a string specifying the given graph in Dot language.

@type  G: graph
@param G: Graph.

@type  weighted: boolean
@param weighted: Whether edges should be labelled with their weight.

@rtype:  string
@return: String specifying the graph in Dot Language.