<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with nodes 0, 1, 2, 3, 4 and edges from each node to the next (i.e., (0, 1), (1, 2), (2, 3), (3, 4)), how can we generate a textual representation of this graph that clearly shows the structure and connections between nodes?
### Response:
import networkx as nx

# Create a directed graph
graph = nx.DiGraph()

# Add some edges
graph.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4)])

# Write the text representation to a string using a callback
result = []
def write_callback(s):
    result.append(s)

# Call the function with the graph and the callback
nx.write_network_text(graph, path=write_callback)

# Print the text representation of the graph
print(''.join(result))
<|EOT|>
