SHARE
TWEET

Untitled

a guest Aug 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person(object):
  2.  
  3.     def __innit__(self):
  4.         self.__name = ""
  5.         self.__surname = ""
  6.         self.__age = 0
  7.  
  8.     def setName(self,name):
  9.         self.name = name
  10.  
  11.     def setSurname(self,surname):
  12.         self.surname = surname
  13.  
  14.     def setAge(self,age):
  15.         self.age = age
  16.  
  17.     def getName(self):
  18.         return self.name
  19.  
  20.     def getSurname(self):
  21.         return self.surname
  22.  
  23.     def getAge(self):
  24.         return self.age
  25.  
  26.     def Details(self):
  27.         return "nName: " + self.name + "nSurname: " + self.surname +
  28.     "nAge: " + str(self.age)
  29.      
  30. class MethodClass:
  31.  
  32.     persList = {}
  33.     counter = 0
  34.  
  35.     def AddPerson(self,personObj):
  36.         MethodClass.persList.update( {MethodClass.counter : personObj} )
  37.         MethodClass.counter += 1
  38.  
  39.     def DeletePerson(self,name):
  40.         for k,v in MethodClass.persList.items():
  41.             if(v.getName() == name):
  42.                 del MethodClass.persList[k]
  43.                 print("Successfully removed " + name)
  44.                 break
  45.  
  46.     def ListPersons(self):
  47.         listings = ""
  48.  
  49.         for k,v in MethodClass.persList.items():
  50.  
  51.             listings += v.Details()
  52.  
  53.         print(listings + "n")
  54.      
  55. import MethodClass,Person
  56. import os.path
  57. import dill
  58.  
  59. class Runner:
  60.     mC = MethodClass.MethodClass()
  61.  
  62.     def SaveFile(mC):
  63.         if(os.path.isfile('database.dat') == False):
  64.             dill.dump(mC, open(b'database.dat','wb'))
  65.             print("nSaving in a new file...n")
  66.         else:
  67.             dill.dump(mC, open(b'database.dat','ab'))
  68.             print("nSaving in an existing file...n")
  69.  
  70.     def LoadFile():
  71.         if(os.path.isfile('database.dat') == True):
  72.             obj = dill.load(open(b'database.dat','rb'))
  73.             print("nLoading file...n")
  74.             return obj
  75.         else:
  76.             print("nFile not found.n")
  77.  
  78.     while True:
  79.  
  80.         print("1. Add Person")
  81.         print("2. Delete Person")
  82.         print("3. List Persons")
  83.         print("4. Save Data")
  84.         print("5. Load Data")
  85.         print("6. Exit")
  86.  
  87.  
  88.         try:
  89.             inp = int(input("Choose an option: n"))
  90.  
  91.         except Exception as e:
  92.             print("Type error: " + str(e))
  93.  
  94.         if(inp == 1):
  95.  
  96.             tmpPer = Person.Person()
  97.  
  98.             tmpPer.setName(input("Enter a name: "))
  99.             tmpPer.setSurname(input("Enter a surname: "))
  100.             tmpPer.setAge(input("Enter age: "))
  101.  
  102.             mC.AddPerson(tmpPer)
  103.  
  104.         elif(inp == 2):
  105.             mC.DeletePerson(str(input("Enter name: ")))
  106.  
  107.         elif(inp == 3):
  108.             mC.ListPersons()
  109.  
  110.         elif(inp == 4):
  111.             SaveFile(mC)
  112.  
  113.         elif(inp == 5):
  114.             mC = LoadFile()
  115.  
  116.         elif(inp == 6):
  117.             print("Cya")
  118.             break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top