difference b/t dictionary{} and anydbm - they seem the same

D

davidj411

anydbm and dictionary{} seem like they both have a single key and key
value.
Can't you put more information into a DBM file or link tables? I just
don't see the benefit except for the persistent storage.

d= dbm.open('c:\\temp\\mydb.dat','n')

It has the following interface (key and data are strings):

d[key] = data # store data at key (may override data at
# existing key)
data = d[key] # retrieve data at key (raise KeyError if no
# such key)
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = key in d # true if the key exists
list = d.keys() # return a list of all existing keys (slow!)
 
C

Carsten Haese

anydbm and dictionary{} seem like they both have a single key and key
value.
Can't you put more information into a DBM file or link tables? I just
don't see the benefit except for the persistent storage.

Persistent storage /is/ the benefit. If you want to store relational
data, you should use a relational database.
 
R

Robert Bossy

davidj411 said:
anydbm and dictionary{} seem like they both have a single key and key
value.
Can't you put more information into a DBM file or link tables? I just
don't see the benefit except for the persistent storage.
Except for the persistent storage, that insignificant feature... ;) Well
I guess that persistent storage must be the reason some people use
anydbm sometimes.

If you want keys and values of any type (not just strings) and
persistent storage, you can use builtin dicts then pickle them.

Cheers,
RB
 
D

davidj411

Persistent storage /is/ the benefit. If you want to store relational
data, you should use a relational database.

Thanks, that makes sense. Are there any local relational databases
available to python that don't require a server backend?
 
D

Dennis Lee Bieber

Are there any that aren't persistent?

SQLite -- when opening a "memory" database rather than giving it a
physical file. {I'm a tad too busy to look up the format of the memory
parameter, but it shouldn't be too difficult to find it}
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

castironpi

Are there any that aren't persistent?
        SQLite -- when opening a "memory" database rather than giving it a
physical file. {I'm a tad too busy to look up the format of the memory
parameter, but it shouldn't be too difficult to find it}

What? If I wanted to code string literals, I'd use exec. Where's the
real one?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top