[Tutor] overriding instance attributes with keywords

Steven D'Aprano steve at pearwood.info
Wed Aug 15 01:48:13 CEST 2012


On 15/08/12 04:25, Matt Gregory wrote:

> Thanks to you both for really helpful advice. A quick follow-up question - would you want to create a deepcopy of obj1 in the above example if your obj1 contained other objects?

Only the person making the copy can answer that question, but in general, shallow copies are more common than deep copies.

Making a deep copy can be relatively expensive, because Python will copy all the way down, as many levels deep as there are. But it's the only way to ensure that each copy is truly independent.


> I think that Steven's class method gets around this?

Only by ignoring it completely :)


-- 
Steven


More information about the Tutor mailing list