As far as I know, there is no utility for this. The built-in copy and deepcopy require objects to provide their __copy__ and __deepcopy__ to override the default behavior. Which is not a good idea IMHO, since you do not always want to have copies of the same type ...
Writing a function for this should not be complicated. Here is an example that works for lists, tuples, and dicts:
def mycopy(obj): if isinstance(obj, list): return [mycopy(i) for i in obj] if isinstance(obj, tuple): return tuple(mycopy(i) for i in obj) if isinstance(obj, dict): return dict(mycopy(i) for i in obj.iteritems()) return obj
source share