Python Clone объект
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]}
import copy
class Example:
def do_something(self): print("Doing a function")
a = Example()
b = copy.deepcopy(a);
b.do_something()
# >>> Doing a function
>>> import copy
>>> a = 0
>>> b = 2
>>> a = copy.copy(b)
>>> b += 1
>>> a
2
>>> b
3