P
P
piffo2020-08-16 00:14:32
Python
piffo, 2020-08-16 00:14:32

How to create a .data file?

I'm learning python from the book "A Byte Python".
There is such a program

import pickle

shoplistfile = "shoplist.data"
shoplist = ["яблоки", "манго", "морковь"]

f = open(shoplistfile)
pickle.dump(shoplist, f)
f.close()

del shoplist

f = open(shoplistfile, "rb")
storedlist = pickle.load(f)
print(storedlist)

When starting the program, it gives an error, supposedly there is no shoplist.data file.
How to create a similar file on Windows 10?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
marshadow, 2020-08-16
@marshadow

Try f = open(shoplistfile, "w")

A
alekssamos, 2020-08-16
@alekssamos

f = open(shoplistfile, "wb")
Wasn't "wb" in the textbook?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question