title: deep copy fires another function - python
body: <p>What I want to happen is anytime I use deep copy on my class 'Node' that it runs the original method for deepCopy and then assigns a new UID to the node. This currently hits a recursion limit. I'm using deepCopy because my class object will expand to contain lists and dictionaries.</p>
  
  <pre><code>import copy
  import uuid
  
  # Classes
  class Node(object):
      def __init__(self, name):
          self.name = name
          self.uid = str( uuid.uuid4( ) )
  
      def __deepcopy__(self, memo):
          _new = (copy.deepcopy(self, memo))
          _new.uid = str( uuid.uuid4( ) )
          return _new
  
  class Truck(Node):
      def __init__(self, name=""):
          super(Truck, self).__init__(name=name)
  
  
  old_truck = Truck( name="Tonka Truck")
  new_truck = copy.deepcopy( old_truck )
  
  print old_truck.uid
  print new_truck.uid
  </code></pre>
  
  <hr>
  
  <p>attempted solution seems to work alright</p>
  
  <pre><code>import copy
  import uuid
  
  # Classes
  class Node(object):
      def __init__(self, name):
          self.name = name
          self.uid = str( uuid.uuid4( ) )
  
      def copy_node(self):
          new_node = copy.deepcopy( self )
          new_node.uid = str( uuid.uuid4( ) )
          return new_node
  
  class Truck(Node):
      def __init__(self, name=""):
          super(Truck, self).__init__(name=name)
  
  
  old_truck = Truck( name="Tonka Truck")
  new_truck = old_truck.copy_node()
  
  print old_truck.uid
  print new_truck.uid
  </code></pre>