Popular recipes tagged "equal"http://code.activestate.com/recipes/tags/equal/2012-02-26T15:43:01-08:00ActiveState Code RecipesMETACLASS AND DEEPCOPY (Python) 2012-02-26T15:43:01-08:00thonpyhttp://code.activestate.com/recipes/users/4181053/http://code.activestate.com/recipes/578053-metaclass-and-deepcopy/ <p style="color: grey"> Python recipe 578053 by <a href="/recipes/users/4181053/">thonpy</a> (<a href="/recipes/tags/deepcopy/">deepcopy</a>, <a href="/recipes/tags/equal/">equal</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/sign/">sign</a>). </p> <p>I would like to solve this excercise: Traditionally object-oriented programming provides two different modes for cloning an instance or a structured data type: shallow and deep copy. The former has the effect to clone exclusively the external shell and not its content originating a quite fastidious aliasing effect. The latter, instead, copies the shell and its content recursively creating two completely separate copies of the instance.</p> <p>As you know, Python's programs suffer of the aliasing effect when you copy an instance of a class or a structured type (e.g., a list) with the = operator. As showed in the following example:</p> <p>l=[0,1,2] mylist=l mylist[2] = ’B’ mylist [1, 2, ’B’] l [1, 2, ’B’</p> <p>The exercise consists of defining a meta-class which implements the deep copy on the assignment operator and binding this to the standard class list. Such that the following behavior can be yielded</p>