Newbie question - deleting records from anydbm database

Steve Holden steve at holdenweb.com
Wed Dec 14 21:10:48 EST 2005


Dan M wrote:
> I've been Googling like a mad fiend and flipping through my hard-copy
> Python books, but still haven't located the one little bit of info I need.
> 
> I've put together a simple SMTP-after-IMAP script that gets the authorized
> IP info from the mail log (I know, it's not elegant but it works). All
> works fine up until I go to scan the database of added IP addresses to
> delete the old ones. The problem is, I don't know how to drop a record
> from an anydbm database!
> 
> The database file in question is compatible with the database built using
> "makemap hash imapauth < imapauth" - in fact, I'm using makemap to check
> the file contents against what I'm expecting.
> 
> I'm adding records with code such as:
>      db = anydbm.open(accessDbPath, "w")
>      db[ipAddress] = str(time.time())
> 
> Now how can I go about deleting that record when it's too old?
> 
(untested)

try

     del db[ipAddress]

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list