while at work i had nothing to do so i wrote this simple python script that uses the dbm module to store user information its not perfect but im sure someone will find it helpful.

import dbm,sys
from time import ctime
class Database(object):
    def __init__(self):

        self.userData = dbm.open("User Data", "c")
        print "\t\tStudent Database Management  System"
        print "\t\t             SDMS"
        print "\t\t....................................\n"

        print "please select option "
        print "(1)Add/Edit User info"
        print "(2)View/Edit"
        print "(3)Remove User Data"

        funcChoice = raw_input("Choice")
        if funcChoice == "1":
        elif funcChoice == "2":
        elif funcChoice == "3":
        elif funcChoice == "e":
            sys.exit("Please come again")

    def Add(self):
        print "\t\tNew User Wizard\n"
        self._Id = raw_input("ID number\n>")
        for key in self.userData.keys():
            if self._Id not in self.userData.keys():
                self.First = str(raw_input("students first name?\n>"))
                self.lastName = str(raw_input("students last name?\n>"))
                self.userData[self._Id] = "Id: "+self._Id +" "+ "Name: "+self.First +" "+self.lastName + str(ctime())

            elif self._Id == key:
                print "Id already found in database"
                print "............................."
                print "Do you want to replace User info for id"
                answer = raw_input(">")
                if answer == "y":
                    self.First = str(raw_input("students first name?"))
                    self.lastName = str(raw_input("students last name?"))
                    self.userData[self._Id] = "Id: "+self._Id+" "+"Name: "+str(self.First)+" " +str(self.lastName)

                elif answer == "n":
                    sans = raw_input("do you want to choose a different user id?\n>")
                    if sans =="n":
                    elif sans == "y":
                    elif sans == "e":
                elif answer == "e":
                    sys.exit("come again")
                    print "please use (y)es or (n)o or (e)xit"


    def View(self):
        print "Please choose how you want to view student info\n\n"
        print "..................................................."
        print "(1)View Individual"
        print "(2)View All"

        viewChoice = raw_input("Choice\n>")
        if viewChoice == "1":
            viewFind = raw_input("\t\tuse student Id to Search\n\n>")
            print self.userData[viewFind]

        elif viewChoice == "2":
            for key in sorted(self.userData.keys()):
                print self.userData[key]

    def Remove(self):
        print "What information do you want to remove\nWARNING!! if you delete any piece of data you wont be able to restore it\n"
        for key in sorted(self.userData.keys()):
                print self.userData[key]
        data = raw_input(">")

        del self.userData[data]

database = Database()

Recommended Answers

If you thinki it is fully working, why not post it as Code Snippet?

Jump to Post

All 2 Replies

If you thinki it is fully working, why not post it as Code Snippet?

im new here so im not sure how to do things fully

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.