Skip to content

Commit

Permalink
fix up pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
MridulS committed Jun 8, 2023
1 parent b6a7672 commit 57d6dd7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions notebooks/03-practical/01-io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,6 @@
"\n",
"Since NetworkX graphs are Python objects,\n",
"the canonical way to save them is by pickling them.\n",
"You can do this using:\n",
"\n",
"```python\n",
"nx.write_gpickle(G, file_path)\n",
"```\n",
"\n",
"Here's an example in action:"
]
Expand All @@ -546,7 +541,9 @@
"metadata": {},
"outputs": [],
"source": [
"nx.write_gpickle(G, \"/tmp/divvy.pkl\")"
"import pickle\n",
"with open(\"/tmp/divvy.pkl\", \"wb\") as f:\n",
" pickle.dump(G, f, pickle.HIGHEST_PROTOCOL)"
]
},
{
Expand All @@ -562,7 +559,8 @@
"metadata": {},
"outputs": [],
"source": [
"G_loaded = nx.read_gpickle(\"/tmp/divvy.pkl\")"
"with open(\"/tmp/divvy.pkl\", \"rb\") as f:\n",
" G_loaded = pickle.load(f)"
]
},
{
Expand Down

0 comments on commit 57d6dd7

Please sign in to comment.