In Python, how to deep copy the Namespace obj "args" from argparse
<p>I got "args" from argparse:</p>

<blockquote>
  <p>args = parser.parse_args()</p>
</blockquote>

<p>I want to pass it to two different functions with slight modifications each. That's why I want to deep copy the args, modify the copy and pass them to each function. </p>

<p>However, the copy.deepcopy just doesn't work. It gives me:</p>

<blockquote>
  <p>TypeError: cannot deepcopy this pattern object</p>
</blockquote>

<p>So what's the right way to do it? Thanks</p>

<p>I myself just figured out a way to do it:</p>

<pre><code>args_copy = Namespace(**vars(args))
</code></pre>

<p>Not real deep copy. But at least "deeper" than:</p>

<pre><code>args_copy = args
</code></pre>

python copy argparse