| 4 | |
| 5 | |
| 6 | class orm(nn.Module): |
| 7 | def __init__(self, data_file="sql/sql.pkl"): |
| 8 | super().__init__() |
| 9 | self.data_file = data_file |
| 10 | |
| 11 | def save(self, sql): |
| 12 | if os.path.exists(self.data_file): |
| 13 | with open(self.data_file, 'ab+') as f: |
| 14 | pickle.dump(sql, f) |
| 15 | f.write(b'\n') |
| 16 | # 如果文件不存在,则创建新文件并写入数据 |
| 17 | else: |
| 18 | with open(self.data_file, 'wb+') as f: |
| 19 | pickle.dump(sql, f) |
| 20 | f.write(b'\n') |