<｜begin▁of▁sentence｜>### Instruction:
Given an undirected or directed graph which you can load from network.gml, can you help me calculate the number of weakly connected components?
### Response:
from igraph import Graph

# Load graph from a file
g = Graph.Read('network.gml')

# Calculate the weak connected components
components = g.connected_components(mode='weak')

# Print the number of weakly connected components
print('Number of weakly connected components:', len(components))
<|EOT|>
