How do I copy, but not deepcopy, a networkx Graph?
<p>I want to compare the state of a <code>networkx.Graph</code> object <code>n</code> before a function call <code>d(n)</code> (with side effects) with the state afterwards.</p>

<p>There are mutable object node attributes such as <code>n.node[0]['attribute']</code>, which I want to compare.</p>

<p>Obviously,</p>

<pre><code>before = n
d()
after = n
assert id(before.node[0]['attribute']) == id(after.node[0]['attribute'])
</code></pre>

<p>succeeds trivially, because</p>

<pre><code>before == after
</code></pre>

<p>but if I set <code>before=n.copy()</code>, a deep copy is made, and therefore <code>id(before.node[0]['attribute']) != id(after.node[0]['attribute'])</code>. How do I get a copy of a Graph object without copying all node attribute objects?</p>