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

Log in
Name

Password

 
 

Folder icon 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]

 Title   Type   Size   Modified   Status 
 Persistent List and Dictionary Edit object Software Release   2000-02-14 published
 Persistent List and Dictionary README Edit object Document 2 K 2000-02-14 published