import cPickle # WHY do I use cPickle instead of Pickle? def pickler(name1, lst): output = open('pickle_jar', 'w') # Open the pickle jar cPickle.dump(name1, output) # Put in a tasty treat cPickle.dump(lst, output) # And another output.close() # Still have to close the file! def unpickler(): '''Opens the pickle jar and loads the contents into some variables. Returns those variables, using multiple return values ''' input = open('pickle_jar', 'r') nm = cPickle.load(input) myList = cPickle.load(input) input.close() return nm, myList def main(): nm1 = 'Vlassic' types = ['sweet', 'hot', 'dill', 99] pickler(nm1, types) nm1, types = unpickler() print 'NM1 is %s, types is %s' %(nm1, types) main()