I need to save about a dozen objects to a file and then restore them later. I've tried to use a for loop with pickle and shelve but it didn't work right.
Edit.
All of the objects that I was trying to save were in the same class (I should have mentioned this before), and I didn't realize that I could just save the whole class like this:
import pickle
def saveLoad(opt):
global calc
if opt == "save":
f = file(filename, 'wb')
pickle.dump(calc, f, 2)
f.close
print 'data saved'
elif opt == "load":
f = file(filename, 'rb')
calc = pickle.load(f)
else:
print 'Invalid saveLoad option'