[Zope-dev] persistence and lists
Casey Duncan
casey@zope.com
Wed, 18 Sep 2002 15:42:29 -0400
Sounds like you are trying to persist a class attribute value. This is no=
t=20
possible because instance are persistent, not classes. This is also the=20
reason that the values change over all the instances. You are changing a=20
mutable attribute of the class in place.
I would suggest setting the value in the constructor of your objects, to =
make=20
sure it is an instance attribute rather than a class attr.
This:
class foo:
def __init__(self):
self.alist =3D []
def append(self ,v)
self.alist.append(v) # changes instance attr
self._p_changed =3D 1 # will work
Instead of:
class foo:
alist =3D []
def append(self ,v)
self.alist.append(v) # changes class(!) attr
self._p_changed =3D 1 # Will not work, the instance was not chang=
ed!
hth,
Casey
On Wednesday 18 September 2002 03:27 pm, Arndt Droullier wrote:
> Hello,
> I=B4m working on a product which contains custom data in a list of mult=
iple
> dictionaries.
> How can I save the list/dictionaries after changes? Persistence is enab=
led
> (and works for other types), and "_p_changed" is set, also
> get_transaction().commit() is called.
>=20
> A second problem is that multiple instances of the product reference th=
e
> same list. So if I change the list of one of the instances the other
> changes,
> too.
> The list and dictionaries are stored in a class variable(in the product=
)
> and not global.
>=20
> Thanks, Arndt.
>=20
> _______________________________________________________________________
> DV electric ad@dvelectric.com http://www.dvelectric.com
> Fon 0221/2725782 Fax 0221/2725783 Burgmauer 20, 50667 K=F6=
ln
> _______________________________________________________________________