You are not logged in Log in Join
You are here: Home » Members » AndrewWilcox » Persistent List and Dictionary

Log in
Name

Password

 
 

Persistent List and Dictionary

The PersistentDict and PersistentList classes implement persistent dictionaries and lists. These recognize when they've been modified, and trigger the ZODB persistence mechanism.

PersistentDict is similar to the PersistentMapping that comes with Zope, but it does not restrict keys to be strings, and does not hide keys that begin with an underscore.

For example, here's a class that uses a regular Python list. Because the ZODB doesn't know when the list has been modified automatically, the programmer needs to trigger persistence by setting one of the object attributes.

    class Myclass (Persistent):
        def __init__(self):
            self.l = [1, 2, 3, 4, 5, 6]

def act(self): l = self.l l[2:4] = [33, 37, 39, 41, 44] self.l = l

By using a PersistentList, the ZODB will know when the list has been changed.

    class Myclass (Persistent):
        def __init__(self):
            self.l = PersistentList([1, 2, 3, 4, 5, 6])

def act(self): self.l[2:4] = [33, 37, 39, 41, 44]

Latest Release: 1.0
Last Updated: 2000-02-14 10:38:56
Author: ZopeOrgSite
Categories: Helpers
Maturity: Stable

Available Releases

Version Maturity Platform Released
1.0 Stable   2000-02-14 10:38:56
  PersistentListDict-1.0.tar.gz (1 K) All