|
@@ -1,4 +1,5 @@
|
|
import misc_class
|
|
import misc_class
|
|
|
|
+import pickle
|
|
|
|
|
|
|
|
|
|
def coin_test():
|
|
def coin_test():
|
|
@@ -26,12 +27,63 @@ def bankaccount_test():
|
|
# Здесь тоже будет вызван метод __str__, но через str()
|
|
# Здесь тоже будет вызван метод __str__, но через str()
|
|
print(str(savings))
|
|
print(str(savings))
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+# Создает 4 объектов CellPhone и сохраняет из в списке
|
|
|
|
+def cellphone_test():
|
|
|
|
+ phone_list = []
|
|
|
|
+
|
|
|
|
+ for _ in range(5):
|
|
|
|
+ phone = misc_class.CellPhone()
|
|
|
|
+ phone_list.append(phone)
|
|
|
|
+
|
|
|
|
+ for item in phone_list:
|
|
|
|
+ print(item.get_manufact())
|
|
|
|
+ print(item.get_model())
|
|
|
|
+ print(item.get_retail_price())
|
|
|
|
+
|
|
|
|
+# Сериализация/десериализация объектов
|
|
|
|
+def cellphone_serial():
|
|
|
|
+ FILE_NAME = 'cellphones.dat'
|
|
|
|
+ file = open(FILE_NAME, 'wb')
|
|
|
|
+
|
|
|
|
+ for _ in range(5):
|
|
|
|
+ phone = misc_class.CellPhone()
|
|
|
|
+ pickle.dump(phone, file)
|
|
|
|
+
|
|
|
|
+ file.close()
|
|
|
|
+ print(f'Данные записаны в {FILE_NAME}')
|
|
|
|
+
|
|
|
|
+ file = open(FILE_NAME, 'rb')
|
|
|
|
+ end_of_file = False
|
|
|
|
+ while not end_of_file:
|
|
|
|
+ try:
|
|
|
|
+ phone = pickle.load(file)
|
|
|
|
+ print(f'Производитель: {phone.get_manufact()}')
|
|
|
|
+ print(f'Номер моделы: {phone.get_model()}')
|
|
|
|
+ print(f'Розничная цена: {phone.get_retail_price()}')
|
|
|
|
+ print()
|
|
|
|
+ except Exception as e:
|
|
|
|
+ end_of_file = True
|
|
|
|
+
|
|
|
|
+ file.close()
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
|
+ #
|
|
# coin_test()
|
|
# coin_test()
|
|
- bankaccount_test()
|
|
|
|
|
|
+
|
|
|
|
+ # Методы __str__
|
|
|
|
+ # bankaccount_test()
|
|
|
|
+
|
|
|
|
+ # Создание списка объектов CellPhone
|
|
|
|
+ # cellphone_test()
|
|
|
|
+
|
|
|
|
+ # Сериализация объектов
|
|
|
|
+ # cellphone_serial()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
main()
|
|
main()
|