This is quite a simple question, however I cannot seem to figure out how to do it. I simply need to make a copy of a class object, for example:
class Foo():
def __init__(self, nums):
self.nums = nums
A = Foo(5)
I tried to do both A.copy() and A.deepcopy(), but I get "'Foo' object has no attribute 'copy'" This may be a super simple fix, however I have never used the copy module before and am not aware of why this may be an issue. For reference, I need the copied object to be mutable (without affecting the original) so I figured the best way would be to use .deepcopy().
copy.deepcopy(A)?def copy(self): return Foo(**vars(self)). If initialization would affect the incoming arguments, something likeinstance = object.__new__(Foo); vars(instance).update(vars(self)); return instancecould work