Exemple #1
0
 def pay(self):
     # 交费
     amount = input("交费金额:").strip()
     student_data = File(
         setting.student_file).file_load()  # 读取student_file数据
     if not student_data.get(self.name):
         student_data[self.name] = self.__dict__  # 如果self.name没有注册,初始化数据
     sum_amount = student_data[self.name]["amount"]  # 以前交费总额
     if amount.isdigit():
         sum_amount += int(amount)  # 加上这次交费,算总额
         student_data[
             self.name]["amount"] = sum_amount  # 加入总额传入student_data中
         File(setting.student_file).file_dump(
             student_data)  # 写入student_file文件
         self.amount = sum_amount  # 总额数赋值给self.amount
         print("\033[32;1m【%s】总缴费【¥%s】\033[0m" % (self.name, self.amount))
     else:
         print("\033[41;1m【%s】格式错误\033[0m" % amount)
Exemple #2
0
 def initializ(self):
     school_data = File(setting.school_file).file_load()
     if not school_data.get(self.school): school_data[self.school] = {}
     school_data[self.school][self.address] = self.__dict__
     File(setting.school_file).file_dump(school_data)