---------- Forwarded message ---------- From: Peter Bengtsson <[EMAIL PROTECTED]> To: Jeff Shell <[EMAIL PROTECTED]> Date: Wed, 15 Feb 2006 13:14:58 +0000 Subject: Re: [Zope3-Users] What attributes are made persistent On 2/15/06, Jeff Shell <[EMAIL PROTECTED]> wrote: > On 2/14/06, Peter Bengtsson <[EMAIL PROTECTED]> wrote: > > D'oh! That's confusing. Isn't there a class that gathers all of these in > > one. > > > > It seems confusing, you derive from Persistent but only some are accepted. > > Does that mean that there's PersistentFloat and PersistentTuple too? > > If not, why *only* dicts? > > As mentioned above, it applies to *mutable* objects. >
> > Instances of Persistent based classes know when they change. Like if you do:: > > clive.age = 28 > > > On the other hand, if you do:: > > clive.favoriteNumbers.append(13) > > 'clive' does not change. 'favoriteNumbers' changes. If favoriteNumbers > is a regular Python list, the persistence machinery has no idea that > it's changed. It's not being assigned to 'clive', it's already an > attribute there and is not being replaced. So if it's not a > PersistentList, it gets forgotten. > > > It's not only dicts, it's dicts and lists (PersistentDict and PersistentList). > > I don't know if there's a PersistentSet. Python offers two sets since > 2.3 - a mutable (list-like) one and an immutable (tuple-like) one. I > imagine that if you use the mutable set (``sets.Set`` in 2.3, ``set`` > in 2.4), you'd run into the same problems. But if you used the > immutable set (``sets.ImmutableSet``, ``frozenset`` in 2.4) you > wouldn't. > > > So - just use PersistentList and PersistentDict (or look into BTrees > for better storage options). > > For more details, visit the ZODB documentation on ZODB programming, > and visit the section on modifying mutable objects: > > http://www.zope.org/Wikis/ZODB/FrontPage/guide/node3.html > I understand the mutation stuff and I always do it like this in zope2 (I'm a complete beginner in the zope3 world eager to learn): def updatesometing(self): #self.numbers['Peter'] = "0779 123 456" numbers = self.numbers numbers['Peter'] = "0779 123 456" self.numbers = numbers But in zope2 land, if I derive from Persistent it magically saves ALL attributes defined in __init__ assuming that I post-write to them correct as shown above. I like this simplicity and was hoping to find it in zope3 land too. I guess I'm just an old dog and if I want to drag with me the zope2 way I can do this:: import persistent.mapping.PersistentMapping import persistent.list.PersistentList import persistent.dict.PersistentDict class PersistentAnything(PersistentMapping, PersistentList, PersistentDict): I'm aware of BTrees and am/will always use it when size of objects becomes "uncontrollable". Am I just trying to make it too simple? Have I read one too many books by Steve Krug? -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users