I've written a basic storage class that holds data in a list of lists writes it to a file and then allows it to be read back from the file for persistence. It was working on the system it was originally written (windows 7) I moved it to a second system (windows 8) and now it seems to be malfunctioning.
The error I'm receiving is:
Traceback (most recent call last):
File "D:\Code Vault\pydb.py", line 69, in <module>
print Users.ReadData()
File "D:\Code Vault\pydb.py", line 23, in ReadData
self.data = cPickle.load(self.Inputstream)
EOFError
The full code for the class is as follows
class table():
#TODO Insert Key Feild to facilitate ID Search
def __init__(self,*args):
self.tablename = args[0]
self.data = []
self.colnames = {}
self.filename = str(self.tablename)+ ".p"
for e in args[1:]:
self.colnames.update({e:len(self.colnames)})
self.Filestorage = open(self.filename, "wb" )
self.Filestorage.close()
def ReadData(self):
self.Inputstream = open(self.filename, "rb")
self.Inputstream.seek(0)
self.data = cPickle.load(self.Inputstream)
self.Inputstream.close()
return self.data
def AddData (self, *args):
self.tempdata = []
for e in args:
self.tempdata.append(e)
if len(args) == len(self.colnames):
self.data.append(self.tempdata)
else:
return "Incorrect argument quantities"
return self.tempdata
def Commit(self):
self.Outputstream = open(self.filename, "ab" )
cPickle.dump(self.data, self.Outputstream)
self.Outputstream.close()
return self.ReadData()
def Search(self,query):
for e in self.ReadData():
if query in e:
return self.ReadData().index(e)
else:
return "Value " + str(query) + " does not exist"
def Update(self,query, edit):
for e in self.data:
if query in e:
e[e.index(query)] = edit
return self.data
def DumpTable(self):
self.data = []
self.Outputstream = open(self.filename+".p", "wb" )
cPickle.dump(self.data, self.Outputstream)
self.Outputstream.close()
self.ReadData()
Users = table("Users","Username","Password")
Users.AddData("bob","123456")
# Users.Commit()
# print Users.data
# print Users.filename
# print Users.data
print Users.ReadData()
It's probably a case of code blindness as it was working previously. Any Ideas would be appreciated