Friday, January 19, 2007

The Tabs

import pickle
class manage:
(tab)def create(self): #creates a new student and assigns them an ID sets ID saves
(tab)(tab)sacred=pickle.load(open("data.tbs", "r"))
(tab)(tab) self.id = sacred["list"]
(tab)(tab) sacred["list"]=sacred["list"] + 1
(tab)(tab) datafile=open("data.tbs", 'w')
(tab)(tab) sacred[self.id]={}
(tab)(tab) pickle.dump(sacred, datafile)

(tab)def setid(self, arg): #sets ID of instance, may not be neccisary
(tab)(tab) self.id=arg
(tab)(tab) self.attrib={}

(tab) def edit(self, name, attribute): #sets names on instance, needs ID set to save
(tab)(tab) try:
(tab)(tab)(tab) self.attrib[name]=attribute
(tab)(tab) except:
(tab)(tab)(tab) self.attrib={}
(tab)(tab)(tab) self.attrib[name]=attribute

(tab) def save(self):
(tab)(tab) sacred=pickle.load(open("data.tbs", "r"))
(tab)(tab) for key in self.attrib:
(tab)(tab)(tab) sacred[self.id][key]=self.attrib[key]
(tab)(tab)(tab) print key, 'corresponds to', self.attrib[key] #for creation use only
(tab)(tab) datafile=open("data.tbs", 'w')
(tab)(tab) pickle.dump(sacred, datafile)

(tab) def open(self, id):
(tab)(tab) sacred=pickle.load(open("data.tbs", "r"))
(tab)(tab) self.attrib= sacred[id]

(tab) def delete(self, id):
(tab)(tab) sacred=pickle.load(open("data.tbs", "r"))
(tab)(tab) del sacred[id]
(tab)(tab) datafile=open("data.tbs", 'w')
(tab)(tab) pickle.dump(sacred, datafile)

#Sorry about all the (tab)'s HTML doesn't support the tab.
#They mean exactly what they say
#I'm currently stuck at the wxPython tool kit. Merh

No comments: