#bll
import pickle
import pandas as pd
class Customer:
cuslist=[]
def __repr__(self):
return(str(self))
def __init__(self):
self.id=0
self.age=0
self.name=0
self.dateofBirth = 0
self.address = 0
self.phoneNumber = 0
self.amount = 0
self.zipCode = 0
self.experience = 0
self.form = 0
def addcustomer(self):
Customer.cuslist.append(self)
def searchcustomer(self):
for e in Customer.cuslist:
if(e.id==self.id):
self.age=e.age
self.name=e.name
self.dateofBirth = e.dateofBirth
self.address = e.address
self.phoneNumber = e.phoneNumber
self.amount = e.amount
self.zipCode = e.zipCode
self.experience = e.experience
self.form = e.form
break
def deletecustomer(self):
for e in Customer.cuslist:
if (e.id == self.id):
Customer.cuslist.remove(e)
break
def updatecustomer(self):
for e in Customer.cuslist:
if(e.id==self.id):
e.age=self.age
e.name=self.name
e.dateofBirth = self.dateofBirth
e.address = self.address
e.phoneNumber = self.phoneNumber
e.amount = self.amount
e.zipCode = self.zipCode
e.experience = self.experience
e.form = self.form
break
@staticmethod
# def convertoExcel(self):
# df = pd.DataFrame(Customer.cuslist.self)
# writer = pd.ExcelWriter('pandas.xlsx', engine='xlsxwriter')
# df.to_excel(writer, sheet_name='Sheet1')
# writer.save()
@staticmethod
def savetoPickle():
f=open("D://cetpa//mypickle.txt","wb")
pickle.dump(Customer.cuslist,f)
f.close()
@staticmethod
def loadfromPickle():
f = open("D://cetpa//mypickle.txt", "rb")
Customer.cuslist=pickle.load(f)
f.close()
#pl
if (__name__ == "__main__"):
while(1):
print("Enter 1 to Add Customer")
print("Enter 2 to Search Customer")
print("Enter 3 to Delete Customer")
print("Enter 4 to Modify Customer")
print("Enter 5 to Display All Customer")
print("Enter 6 to Exit")
ch = input("Enter A Number: ")
if(ch=='1'):
cus=Customer()
cus.id=input("enter id: ")
cus.age = input("enter age: ")
cus.name = input("enter name: ")
cus.dateofBirth = input("enter date of birth: ")
cus.addcustomer()
print("Added Successfully!!")
elif(ch=="2"):
cus=Customer()
cus.id=input("Enter Customer ID: ")
cus.searchcustomer()
print("Customer ID: ",cus.id, "Customer Age: ", cus.age, "Customer Name: ",cus.name)
elif(ch=="3"):
cus=Customer()
cus.id=input("Enter Customer ID: ")
cus.deletecustomer()
print("Entry Deleted!!")
elif(ch=='4'):
cus=Customer()
cus.id=input("Enter Customer ID: ")
cus.age=input("Enter Updated Customer Age: ")
cus.name=input("Enter Updated Customer Name: ")
cus.updatecustomer()
print("Customer Updated Successfully!!")
elif(ch=='5'):
cus=Customer()
for e in Customer.cuslist:
print("Customer ID: ",e.id)
print("Customer Age",e.age)
print("Customer Name: ",e.name)
print("Customer Date of Birth: ",e.dateofBirth)
elif (ch == '6'):
Customer.savetoPickle()
elif (ch == '7'):
Customer.loadfromPickle()
elif (ch == '8'):
print(Customer.cuslist)
-
What is the problem you are facing Or i should ask what you have tried till now? My simple suggestion will be to search for python library which can help you exporting data in excel and integrate it in your code – anuragal Oct 27 '20 at 5:55
Add a comment
|
Look into openpyxl.
It's a python module that lets you do stuff like this:
from openpyxl import Workbook
book = Workbook()
sheet = book.active
sheet['A1'] = "name"
sheet['A2'] = customer1.name
sheet['A3'] = customer2.name
sheet['B1'] = "age"
sheet['B2'] = customer1.age
sheet['B3'] = customer2.age
book.save("my_excel_file.xlsx")