Python - AttributeError: 'function' object has no attribute 'deepcopy'
python
Solution
I am facing the same problem, and tried many ways. The following way resolves my problem: change
import copy
dict = {...}
copy.deepcopy()
to
from copy import deepcopy
dict = {...}
deepcopy()
Problem
I have a list of mutable objects which is an attribute of a class. ``` self.matriceCaracteristiques ``` I would like to keep a copy of it, so that the objects will change during execution as for the original list, but not their order in the list itself (that is what I want to preserve and "restore" after execution). ``` copy_of_matCar = self.matriceCaracteristiques[:] #to preserve the order of the objects #that will be changed during execution ``` When it's time to restore the list, I've tried making this: ``` self.matriceCaracteristiques = copy_of_matCar[:] ``` but it doesn't work cause although the `copy_of_matCar` has a different order (specifically, the one that the attribute had before some code execution), the other `self.matriceCaracteristiques` remains exactly the same although the instruction. So I have thought to make a deepcopy of it, by following the Python reference: ``` import copy self.matriceCaracteristiques = copy.deepcopy(copy_of_matCar) ``` However, what I get is the following error: ``` self.matriceCaracteristiques = copy.deepcopy(copy_of_matCar) AttributeError: 'function' object has no attribute 'deepcopy' ``` Any idea how I can fix this problem and get a deepcopy of the list `copy_of_matCar` to be assigned to the `self.matriceCaracteristiques` one?