anydbm, gdbm, dbm

L

Lacrima

Hello!

I want to store some data, using anydbm module.
According to docs the object returned by anydbm.open() supports most
of the same functionality as dictionaries; keys and their
corresponding values can be stored, retrieved, and deleted...

I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?

Suppose my table consists of two columns: 'first name' and 'last
name'. How can I make such table and write there first and last names
for, say, two any persons?

Thanks in advance...
 
T

Tim Chase

Lacrima said:
I want to store some data, using anydbm module.
According to docs the object returned by anydbm.open() supports most
of the same functionality as dictionaries; keys and their
corresponding values can be stored, retrieved, and deleted...

I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?

Yes, all data for the dbm variants is purely string->string
mapping pairs. Similarly, dictionaries don't natively allow you
to store columns in them...they are just key->value data-stores.
Suppose my table consists of two columns: 'first name' and 'last
name'. How can I make such table and write there first and last names
for, say, two any persons?


*dbm provides no columns unless you hack them such as

db[key] = DELIMITER.join([lastname, firstname])

and then unhack them:

lastname, firstname = db[key].split(DELIMITER, 1)

As a variant of this, you might be able to use pickle/shelve to
stash your multi-content object as a string-value.

Alternatively, you could use something like

db["%s_first" % key] = firstname
db["%s_last" % key] = lastname

assuming your keys didn't confound you.

-tkc
 
L

Lacrima

Lacrima said:
I want to store some data, using anydbm module.
According to docs the object returned by anydbm.open() supports most
of the same functionality as dictionaries; keys and their
corresponding values can be stored, retrieved, and deleted...
I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?

Yes, all data for the dbm variants is purely string->string
mapping pairs.  Similarly, dictionaries don't natively allow you
to store columns in them...they are just key->value data-stores.
Suppose my table consists of two columns: 'first name' and 'last
name'. How can I make such table and write there first and last names
for, say, two any persons?

*dbm provides no columns unless you hack them such as

   db[key] = DELIMITER.join([lastname, firstname])

and then unhack them:

   lastname, firstname = db[key].split(DELIMITER, 1)

As a variant of this, you might be able to use pickle/shelve to
stash your multi-content object as a string-value.

Alternatively, you could use something like

   db["%s_first" % key] = firstname
   db["%s_last" % key] = lastname

assuming your keys didn't confound you.

-tkc

Hi!

Thanks a lot! You've helped me very much!
 
L

Lawrence D'Oliveiro

In message <b0ec6512-ac80-4372-
I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?

Maybe you should look at sqlite instead.
 

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,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top