Dec-19-2018, 05:30 PM
Well I'm pretty novice at OOP so I thought I'd take one of my working non-OOP version of a Pickle program and create this object-oriented version:
Any suggestions? I'm really stumped at the moment.
import pickle '''An object-oriented example of file pickling.''' class Pickles: def __init__(self, count, coomo, f): self.count = count self.coomo = coomo self.f = f def to_pickle(self): pickle.dump(self.count, self.f) pickle.dump(self.coomo, self.f) def __del__(self): f.close() f = open('pickles1.dat', 'wb') count = ['vun', 'two', 'three'] coomo = ['om', 'nom', 'nom']The problem is that it doesn't work. It doesn't throw any errors, but when I use an un-pickling program to open the pickled file, I get an error stating the following:
Error:Traceback (most recent call last):
File "picklingun_ex.py", line 7, in <module>
count = pickle.load(f)
EOFError: Ran out of input
I took a look at the location of the pickles1.dat file and it wasn't saved as a binary file, but a plaintext file. So it seems that I've done something wrong with my object-oriented Pickling program, but I'm not sure what.Any suggestions? I'm really stumped at the moment.
