Creating a shallow copy of an instance of a class inheriting from collections.OrderedDict
<p>I have a class inheriting from <code>collections.OrderedDict</code> with an initializer that takes a positional argument <em>without default</em>. My goal is to create a <em>shallow</em> copy of the instance. However, my initial naive approach below does not work and raises a type error as the positional argument must be supplied when building the new instance.</p>

<pre><code>class B(collections.OrderedDict):

def __init__(self, whatever):
    super().__init__()
    self.whatever = whatever

b = B(3)
b.update({'a':1})
print(b.copy())
</code></pre>

<p>A solution could be to add:</p>

<pre><code>def copy(self):
    new = collections.OrderedDict(self)
    new.whatever = self.whatever
    return new
</code></pre>

<p>But this becomes unwieldy when the number of attribute grows. Is there a better, more direct solution to this problem?</p>

<p><strong>EDIT</strong>:
I am using Python 3.5</p>

<p>you can use python <a href="https://docs.python.org/2/library/copy.html" rel="nofollow">copy</a> library:</p>

<pre><code>copied_object = copy.copy(b)
</code></pre>

python