Just stumbled on this again this morning looking for emancipation... http://www.python.org/doc/current/lib/lib.html Cheers, Paz -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of p.t. Sent: Thursday, June 13, 2002 11:38 AM To: Chris McDonough Cc: Zope Users Subject: Re: [Zope] Python script: problem with session First of all, thanks Chris and David for the explanations: now things are really more understandable to me and I can devise a suitable way to work around the problem. Next, where is the Python doc referenced? Library reference? Language reference? Something else? Finally: does a "deepCopy()" method exist? This would make things easier when storing objects in SESSION: I beleave that (genarally speaking) assigning values to SESSION should be given an option if it is a reference or a deep copy, because SESSION is a temporary repository to be used to "remember" values relevant to object attributes which often are used in a LIFO stack fashion with the same name (polimorphic approach), but independetly managed by different procedure. p.t. At 01:44 PM 6/12/2002 -0400, Chris McDonough wrote:
The copy method of a dictionary returns a "shallow" copy of the dictionary. If you are changing elements of the dictionary that are themselves mutable, you will still have problems. Here are the rules (from the Python docs):
The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):
a.. A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.
b.. A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. Providing you with more information would require that we know all the items in the 'foo' dictionary. If any of them is mutable, and you're changing it, you would see the behavior you describe.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )