pythoncopyargparse

In Python, how to deep copy the Namespace obj "args" from argparse


I got "args" from argparse:

args = parser.parse_args()

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.

However, the copy.deepcopy just doesn't work. It gives me:

TypeError: cannot deepcopy this pattern object

So what's the right way to do it? Thanks


Solution

  • I myself just figured out a way to do it:

    args_copy = Namespace(**vars(args))
    

    Not real deep copy. But at least "deeper" than:

    args_copy = args