Very Stupid Newbie Question Regarding Databases
Thomas Weholt
thomas at bibsyst.no
Tue Dec 21 11:34:53 EST 1999
55wgm_guy at my-deja.com wrote:
>
> Okay, Im obviously new to the Python world, but I have a project Im
> working on that will require databases. In particular, I want to store
> multiple records in the format:
>
> Name:
> Email:
> Phone Number:
> (etc)
>
> Im starting to look at the gdbm, dbm, and anydbm modules. However, it
> seems to me that to store records in the above format would require
> some sort of key to retrieve a particular record. How can the *dbm
> modules do this?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
You could create an object too, like this :
class person_record(name, email, phone):
def __init__(self, name, email, phone):
self.name = name
self.email = email
self.phone = phone
to store them in a database, use shelve:
import shelve
db = shelve.open('database','cw')
person = person_record("thomas","thomas at bibsyst.no","1-800-Python")
to store by a persons name :
db["thomas"] = person
or by phone :
db["1-800-python"] person
db.close()
More information about the Python-list
mailing list