Handling graph objects in Python with NetworkX