title: Generator methods, deepcopy and copy
body: <p>I am trying to avoid the use of deepcopy in a custom class (a Graph class)</p>
  
  <p>The graphs have few attributes, such as vertices, edges, etc. and several generator methods (methods with <code>yield</code>).</p>
  
  <p>I need to copy the graph: e.g.  <code>H = deepcopy(G)</code> but not using deepcopy in order to speed up the program.</p>
  
  <p>Then:</p>
  
  <ul>
  <li><p>If I do not use <code>deepcopy</code> then the
  generator methods in the new graph <code>H</code>
  do not get the current state of the
  generator methods in graph <code>G</code>.</p></li>
  <li><p>If I do not use generator methods and
  opt for using full list generator,
  then I will waste computation time
  doing nothing useful.</p></li>
  </ul>
  
  <p>The solution was to try to <code>deepcopy</code> some specific generator methods, but I get errors.</p>
  
  <p>It seems that the generators save references to, e.g. the vertices and edges of <code>G</code> and then when deepcopied to <code>H</code> the generators in <code>H</code> are still referencing the attributes of <code>G</code> (this sounds logical).</p>
  
  <p>So, am I condemned to use <code>deepcopy</code> after all or not use generator methods?</p>
  
  <p>Is there a third pythonic way?</p>