Setting up how the Python `copy` module handles my objects

From the copydocumentation :

Classes can use the same interfaces to control the copy that they use to control etching.

[...]

So that a class can define its own copy implementation, it can define special methods __copy__()and__deepcopy__()

So who is this? __setstate__()and __getstate__(), which are used for etching, or __copy__()and __deepcopy__()?

+3
source share
2 answers

: __copy__, copy.copy ( __deepcopy__ copy.deepcopy). , , ( , , __getstate__ __setstate__; "Python " ( @ilfaraone ).

+7

__setstate__() __getstate__().

, , , .

Python , Python.

+1

Source: https://habr.com/ru/post/1717194/


All Articles