I'm taking all the filenames in a certain directory in a list
, and would like to write this list in a pickle
file. Here's the code I am using:
import _pickle as pickle
with open(filepath+'filenames.pkl', 'wb') as f:
pickle.dump(filenames, f)
This gives me the following error:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-32-c59e6889d2fe> in <module>()
1 import _pickle as pickle
----> 2 with open(dpath+'filenames.pkl', 'wb') as f:
3 pickle.dump(filenames, f)
FileNotFoundError: [Errno 2] No such file or directory: '/data/train/filenames.pkl'
I am supposed to create this file. Why is this file expected already?
(I'm using Python 3.6.)