I was expecting to be able to do something like:
a = SimpleNamespace(x='test')
b = a.copy()
or maybe:
b = SimpleNamespace(a)
My current solution, which seems to work fine is
b = SimpleNamespace(**a.__dict__)
But it looks somewhat hacky. Is there a more "correct" way?
I don't need a deep copy.
I wanted to use do a deepcopy of a SimpleNamespace. A simple and easy to read way is to use the copy module.
new_namespace = copy.copy(namespace)
or
new_namespace = copy.deepcopy(namespace)
depending on what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With