[Spambayes] Persisting a pickled bayes database

Tim Stone - Four Stones Expressions tim@fourstonesExpressions.com
Sat Nov 9 00:55:07 2002

I can see the nice createbayes function in hammie, but I don't see any 
persistence function anywhere.  I do see several places where code to write a 
pickled bayes database is hard coded, and I understand the PersistentBayes 
thing.  I might be missing something...

I've been using a simple class to handle creating and persisting my bayes 
databases.  I *think* this stuff should probably go somewhere, but beats me 
where... classifier?  doesn't make much sense there... hammie?  Any ideas 

Here's the class...  (kinda a dumb name  ;))

class BayesHelper:
    '''helper class for bayes databases'''
    def __init__(self, db_name, useDB):
       ''' constructor '''
       self.db_name = db_name
       self.useDB = useDB
       self.bayes = hammie.createbayes(db_name, useDB)

    # no __del__() method, because we don't *necessarily* want to persist

    def persist(self):
        '''store the bayes database'''
        if not self.useDB:
           fp = open(self.db_name, 'wb')
           pickle.dump(self.bayes, fp, 1)

- TimS

More information about the Spambayes mailing list