objet de clone python
import copy
new_ob = copy.deepcopy(old_ob)
Sasso
import copy
new_ob = copy.deepcopy(old_ob)
>>> import copy
>>> nums = [1, 2, 3]
>>> data = {'a': 10, 'b': nums}
>>> data
{'a': 10, 'b': [1, 2, 3]}
>>> data_copy = copy.copy(data)
>>> data_deep = copy.deepcopy(data)
>>> data_copy
{'a': 10, 'b': [1, 2, 3]}
>>> data_deep
{'a': 10, 'b': [1, 2, 3]}
>>> data_copy['a'] += 2
>>> nums[1:1] = [254]
>>> data
{'a': 10, 'b': [1, 254, 2, 3]}
>>> data_copy
{'a': 12, 'b': [1, 254, 2, 3]}
>>> data_deep
{'a': 10, 'b': [1, 2, 3]}
from shutil import copyfile
copyfile(src, dst)
org_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
new_list = org_list.copy()
# For lists in lists you need deepcopy()
import copy
org_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
new_list = copy.deepcopy(org_list)