1

__deepcopy__メソッドを定義するオブジェクトがあります。指定されたメソッドではなく、クラスのオブジェクトがコピーされるデフォルトの方法でディープコピーする関数が欲しいですobject

どうすればそれができますか?私はそれをコーディングしようとすることができると思いますが、おそらく私が考えていない多くの「落とし穴」があるでしょう.

私がそうしているのは、__deepcopy__メソッドを実装するオブジェクトクラスがあり、そのメソッドが何らかの条件をチェックし、場合によっては特定の方法でオブジェクトをディープコピーし、他の場合にはディープコピーするためです。デフォルトobjectの方法。

4

1 に答える 1

4

You basically need to override the existing __deepcopy__ method, which means temporarily setting the object's class to something different -- whether that's acceptable essentially depends on whether the "__deepcopy__ override" needs to affect only one, "top-level" object (in which case the kludge's probably OK), or if there are many objects of that class in the graph you're copying, in which case it's quite a mess. Which case obtains?

于 2009-12-19T17:50:46.453 に答える