import pickle class Sell: def __init__(self, shop_id, seller_id,buyer_id, goods_id, price, n): self.shop_id = shop_id self.seller_id = seller_id self.buyer_id = buyer_id self.goods_id = goods_id self.price = price self.n = n def Read_info_Sell(self,m): self.shop_id = int(input("Enter shop's id: ")) self.seller_id = int(input("Enter seller's id: ")) self.buyer_id = int(input("Enter buyer's id: ")) for i in range(m): self.goods_id.append(int(input("Enter goods id: "))) self.price.append(float(input("Enter sell's price: "))) self.n.append( int(input("Enter n: "))) def Show_info(self): print("shop_id: ", self.shop_id, " , ", "seller_id: ", self.seller_id, " , ", "buyer_id: ", self.buyer_id, " , ","goods_id: ", self.goods_id, " , ", "price: ", self.price, " , ", "number is:", self.n) def write_file(list_sell1, n): file = open('D:\\Sell', 'wb') for i in range(n): pickle.dump(list_sell1[i], file) file.close() def Read_file(n): list_sell1 = [] file = open('d:\\Sell', 'rb') for i in range(n): list_sell1.append(pickle.load(file)) file.close() return list_sell1 def sort(list_sell, n): for i in range(n): for j in range(n): if list_sell[i].buyer_id < list_sell[j].buyer_id: temp = list_sell[i] list_sell[i] = list_sell[j] list_sell[j] = temp return list_sell list_sell = [] for i in range(0, 3): sell = Sell(0, 0, 0, [], [], []) sell.Read_info_Sell(2) list_sell.append(sell) list_sell= sort(list_sell, 3) write_file(list_sell, 3) list_sell = Read_file(3) for i in range(0, 3): list_sell[i].Show_info()