Hary
Hary

Reputation: 1217

How to save a pickle file in python in a physical folder

I am new to using pickle in python.

This is how I dump data in a pickle file

result = "123"
pickle.dump(result, open("result.p","wb"))

I am able to read this file using

pickle.load(open("result.p", "rb"))

Now what I am not able to see is the physical pickle file result.p after I dump data in to it. My question is: where does this pickle file get stored after serialized data is dumped in to it.

Upvotes: 0

Views: 6484

Answers (1)

Ashalynd
Ashalynd

Reputation: 12563

You can do one of the two things:

1) Find out what is the working directory for your program / Python interpreter session. This is where this file is created.

One of the ways to do it (from the Python interpreter):

import os
os.getcwd()

2) Provide full path to the "open" function instead of only the filename part, in which case it would create the file where you specify it to be created.

Upvotes: 4

Related Questions