Is it posible to only deep copy a certain types of object, such as a list, a dict, or a tuple
Example: [[1, <SomeObj>], <OtherObj>]
I want to deep copy the first list (and of course.. the 1), but not SomeObj or OtherObj. Those should stay as refereces.
Is that possible to do that with some function that i’m not familiar with or do i have to write my own function?…
As far as I know, there’s no utility to do that. The built-ins
copyanddeepcopyrequire that objects provide their own__copy__and__deepcopy__methods to override the default behavior. Which is not a good idea IMHO, since you don’t always want the same kind of copies…Writing a function to do that shouldn’t be hard, though. Here’s an example that works for lists, tuples and dicts: