Pickle (англ. консервировать, мариновать) — модуль сериализации и десериализации объектов в Python для последующей их передачи.
import pickle
file = "file.out"
data = [120, 64, 97]
with open(file, "wb") as f:
pickle.dump(data, f)
with open(file, "rb") as f:
data = pickle.load(f)
print(data)
Чтение и запись бинарного файла |
Pickle |
file_name = "file.out" data = [120, 64, 97] file_name = "file.out" byteData = bytearray(data) with open(file_name, "wb") as f: f.write(byteData) with open(file_name, "rb") as f: data = f.read() list_data = list(data) print(list_data) |
import pickle, os file = "file.out" data = [120, 64, 97] with open(file, "wb") as f: pickle.dump(data, f) with open(file, "rb") as f: data = pickle.load(f) print(data) |