database based on shelve file : Shelve : Database PYTHON TUTORIALS


PYTHON TUTORIALS » Database » Shelve »

 

database based on shelve file


import sys, shelve

def store_person(db):
    pid = raw_input('Enter unique ID number: ')
    person = {}
    person['name']  = raw_input('Enter name: ')
    person['age']  = raw_input('Enter age: ')
    person['phone'] = raw_input('Enter phone number: ')

    db[pid= person

def lookup_person(db):
    pid = raw_input('Enter ID number: ')
    field = raw_input('What would you like to know? (name, age, phone)  ')
    field = field.strip().lower()
    print field.capitalize() ':', db[pid][field]

def enter_command():
    cmd = raw_input('Enter command (for help)')
    cmd = cmd.strip().lower()
    return cmd

database = shelve.open('c:\database.dat')
store_person(database)
lookup_person(database)
database.close()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Database
» Shelve