On 05/07/07, Sara Johnson <[EMAIL PROTECTED]> wrote:
> This may sound silly, but when writing a program where there is a pickle
> file, how does that get included into the entire program?  For instance;

Hi Sara,

You create pickles with pickle.dump and you read them with pickle.load.

For example:

####### create.py #######

import pickle

data = ['one', 'two', 'three']
outfile = open('data.pickle', 'wb')
pickle.dump(data, outfile)
outfile.close()
#################

######## load.py ########

import pickle
infile = open('data.pickle')
data = pickle.load(infile)
print data
#################

If you run the first script, it will create a pickle of the list
['one', 'two', 'three'].  You'll be able to see the file in the
directory where you ran the script; you can even look at it if you
like.  The second script will read the pickle and reconstruct the
list.

Hope this helps!

-- 
John.
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to