Pickle module file location

I don’t know how many of you are familiar with the pickle module for saving data to text files, but I’m not sure how to specify where the text file should be saved to. I am using it within the GE, and the process is as follows:

import pickle

data = (define what you want to save here)
file = open("save_file","wb")

pickle.dump(data,file)
file.close()

The function “open” specifies the name of the saved file and method of writing it (“wb” being ‘write binary’). If you input “rb”, then it would read the data from the file instead of writing it.

So how would I go about specifying where to save the file? Right now it saves the file to my C drive user folder (windows). Thanks for any help!

~~Stu

if you do not specify where to save it,it will save in the directory it was executed in.
so you will have to specify the path you want in your script

so

import pickle

pkl_file = "c:\path	o\file" #change this to your desired folder & file name
data = (define what you want to save here)
file = open(pkl_file,"wb")

pickle.dump(data,file)
file.close()

That would work, only now the file name (in quotes) has been replaced by a file path. How would I specify the name?

~~Stu

your kind of losing me here,
in the above example you would be hardcoding the path and filename in one go,
if you want to have an independent variable for the filename
you would need to change a few things

pkl_path = “c:”
filename = “myfilename”
file = open(pkl_path+filename,“wb”)

that would put your data in file located at c:\myfilename

Awesome, that’s what I was looking for. Thanks a lot!

~~Stu