title: Is there a decent way of creating a copy constructor in python?
body: <p>I realize questions quite similar to this have been asked, though not exactly this way.</p>
  
  <p>I'd like to have an optional argument for the constructor of my class that, if it is an instance of my class, will be copied.  For example, something like (<em>I know this code does not work!</em>):</p>
  
  <pre><code>class Foo(object):
      def __init__(self, foo=None):
          self.x = None
          self.y = None
          self.z = None
  
          if foo is not None and isinstance(foo, Foo):
              self = copy.deepcopy(foo)
  
  a = Foo()
  a.x = 1
  a.y = 2
  a.z = 3
  
  b = Foo(a)
  print b.x
  print b.y
  print b.z
  </code></pre>
  
  <p>I know there are a few practical solutions to this.  I could set each attribute of self according to the value of foo's corresponding attribute, but this would be really annoying because my class has many, many attributes.  Or I could simply use do:</p>
  
  <pre><code>b = copy.deepcopy(a)
  </code></pre>
  
  <p>...But I'd rather not if that is possible.  I'm also hoping to avoid overriding <code>__new__</code>.</p>
  
  <p>Is there really no decent way at all in python to create a copy constructor?</p>