Start New Discussion within our Software Development Community

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":
                self.Add()
            elif funcChoice == "2":
                self.View()
            elif funcChoice == "3":
                self.Remove()
            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":
                            sys.exit()
                        elif sans == "y":
                            self.Add()
                        elif sans == "e":
                            exit()
                    elif answer == "e":
                        sys.exit("come again")
                    else:
                        print "please use (y)es or (n)o or (e)xit"
    
    
            return
    
        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]
            pass
    
    
    
    
    database = Database()