Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > anydbm, gdbm, dbm

Reply
Thread Tools

anydbm, gdbm, dbm

 
 
Lacrima
Guest
Posts: n/a
 
      10-27-2009
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...
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      10-27-2009
Lacrima wrote:
> 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




 
Reply With Quote
 
 
 
 
Lacrima
Guest
Posts: n/a
 
      10-28-2009
On Oct 27, 4:36*pm, Tim Chase <(E-Mail Removed)> wrote:
> Lacrima wrote:
> > 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!
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-28-2009
In message <b0ec6512-ac80-4372-
http://www.velocityreviews.com/forums/(E-Mail Removed)>, Lacrima wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ImportError: No module named dbm Python 0 10-13-2005 04:04 AM
Best dbm to use? Python 1 09-07-2005 10:22 PM
Sorting entries in a DBM hash by one of the variables Topher Perl 1 01-21-2004 02:28 PM
dbm under Windows Andrew Chalk Python 0 09-05-2003 09:48 PM
dbm file locking with different versions of perl Matt Johnson Perl 0 08-08-2003 11:58 AM



Advertisments