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

Log in
Name

Password

 

Persistent List and Dictionary README

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

The 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]