user interface - Python GUI, on saving calculated output -


i'am making application electrical calculations. provide input, calculations done within class called earthcalc(frame), , have called class as:

root = tk() c = earthcalc(root) 

now, class i'm trying save calculated outputs dictionary [defined outside class] may able save output in notepad. not working! have saved input data output data blank:

def save_data():      filename = tkfiledialog.asksaveasfilename(initialfile='untitled.txt',defaultextension=".txt",filetypes=[("all files","*.*"),("text documents","*.txt")])     try:         file = open(filename, 'w')         mydata = {"conductor material" : c.conductor_material.get(), "soil resistivity" : c.a.get(), "earth fault current" : c.b.get(), "fault clearance time" : c.c.get(), "electrode type" : "pipe", "electrode length" : c.d.get(), "diameter of pipe" : c.e.get(), "initial temperature" : c.f.get(), "conductor strip length" : c.g.get(), "conductor strip width" : c.h.get(), "conductor strip thickness" : c.i.get(), "earth grid burial depth" : c.j.get(), "current division factor" : c.sf.get(), "decreament factor" : c.df.get(), "surface layer resistivity" : c.slr.get(), "surface layer thickness" : c.slt.get(), "weight catagory" : c.weight_catagory.get()}         myop = {"number of pits" : c.pits}         #myop = {"number of pits" : c.pits, "protective conductor cross section" : c.cross_section, "earth grid resistance" : c.grid_resistance, "maximum grid current" : c.maximum_grid_current, "surface layer derating factor" : c.sldf, "touch potential criteria" : c.tpc, "step potential criteria" : c.spc, "ground potential rise" : c.gpr, "grid area" : c.area1}         #textoutput = "input data \nconductor material: %s \nsoil resistivity: %s \nearth fault time: %s \nfault clearance time: %s \nlength of pipe: %s \ndiameter of pipe: %s \ninitial temperature: %s \nconductor strip length: %s \nconductor strip width: %s \nconductor strip thickness: %s \ngrid burial depth: %s \ncurrent division factor: %s \ndecreament factor: %s \nsurface layer resistivity: %s \nsurface layer height: %s \nweight catagory: %s \n\n\noutput data " %self.conductor_material.get(), %self.a.get(), %self.b.grt(), %self.c.get(), %self.d.get(), %self.e.get(), %self.f.get(), %self.g.get(), %self.h.get(), %self.i.get(), %self.j.get(), %self.sf.get(), %self.df.get(), %self.slr.get(), %self.slt.get(), %self.weight_catagory.get()         file.write("input data\n\n")         line in mydata:             file.write(line + ": " + mydata[line] + "\n")         file.write("\n\noutput data \n\n")         file.write(myop["number of pits"])         #for item in myop:             #file.write(myop[item]) 

help me resolve this. please

there few potential problems code. if using python 2.x should avoid variable name "file" since pre-defined class, work in short snippet, might give weird bugs in other cases. name file fine in python3 though.

it bit problematic don't show in except block since crash (for example if number of pits number.write return typeerror) in turn might lead program crashing before data have been flushed disk.

i write this:

def save_data():    filename = tkfiledialog.asksaveasfilename(initialfile='untitled.txt',defaultex»tension=".txt",filetypes=[("all files","*.*"),("text documents","*.txt")])     try:       open(filename,'w') f:          mydata = {"conductor material" :...          myop = {"number of pits" : c.pits}          f.write("input data\n\n")          line,value in mydata.iteritems():             f.write("{0} : {1}\n".format(line, value ))          f.write("\n\noutput data \n\n")          f.write(str(myop["number of pits"]))    except ioerror e:       print "error opening or writing {0}: {1}".format(filename,e.message) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -