Advertisements
Advertisements
प्रश्न
Write a function that writes a structure to disk and then reads it back and display on screen.
कोड लेखन
Advertisements
उत्तर
A Python structure such as a dictionary can be stored and retrieved using the pickle module.
import pickle
def write_read_structure():
record = {
"code": 101,
"name": "Notebook",
"price": 50,
"quantity": 10
}
with open("item.dat", "wb") as file:
pickle.dump(record, file)
with open("item.dat", "rb") as file:
retrieved_record = pickle.load(file)
print(retrieved_record)
write_read_structure()shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
