[Tutor] create an xls file using data from a txt file
I have the following txt file that has 4 fields that are tab separated: the first is the id and the other three show the results per test. 152 TEST1 valid TEST3 good TEST2 bad 158 TEST2 bad TEST1 bad TEST4 valid . . . Based on the above txt I need to create an xls file having as headers ID, TEST1, TEST2, TEST3, TEST4 and the values valid, bad, etc under the corresponding column: ID TEST1 TEST2 TEST3 TEST4 152 valid bad good 158 bad bad valid I tried to work that out with xlwt but couldn't. Actually, I started working on the following script but I couldn't even split the line for further processing: import xlwt wbk = xlwt.Workbook() sheet = wbk.add_sheet('sheet 1') row = 0 f = open('C:/test.txt','r') for line in f: # separate fields by tab L = line.rstrip().split('\t') #actually some code is needed here to create the columns and put the values under the appropriate column . # Write the data, using the style defined above. sheet.write(row,0,ID) sheet.write(row,1,TEST1) sheet.write(row,2,TEST2) sheet.write(row,3,TEST3) sheet.write(row,4,TEST4) row += 1 wbk.save('data.xls') Thanks in advance for any help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter progress bar not responding when moved
I am trying to use a progress bar for my application and used the following code by Michael Lange ( http://tkinter.unpythonic.net/wiki/ProgressMeter?action=PackagePages). However, the progress bar stops responding when I move it. I haven't modified class declaration and _demo but created my own modified function []: class Meter(Tkinter.Frame): def __init__(self, master, width=300, height=20, bg='white', fillcolor='orchid1',\ value=0.0, text=None, font=None, textcolor='black', *args, **kw): Tkinter.Frame.__init__(self, master, bg=bg, width=width, height=height, *args, **kw) self._value = value self._canv = Tkinter.Canvas(self, bg=self['bg'], width=self['width'], height=self['height'],\ highlightthickness=0, relief='flat', bd=0) self._canv.pack(fill='both', expand=1) self._rect = self._canv.create_rectangle(0, 0, 0, self._canv.winfo_reqheight(), fill=fillcolor,\ width=0) self._text = self._canv.create_text(self._canv.winfo_reqwidth()/2, self._canv.winfo_reqheight()/2,\ text='', fill=textcolor) if font: self._canv.itemconfigure(self._text, font=font) self.set(value, text) self.bind('', self._update_coords) def _update_coords(self, event): '''Updates the position of the text and rectangle inside the canvas when the size of the widget gets changed.''' # looks like we have to call update_idletasks() twice to make sure # to get the results we expect self._canv.update_idletasks() self._canv.coords(self._text, self._canv.winfo_width()/2, self._canv.winfo_height()/2) self._canv.coords(self._rect, 0, 0, self._canv.winfo_width()*self._value, self._canv.winfo_height()) self._canv.update_idletasks() def get(self): return self._value, self._canv.itemcget(self._text, 'text') def set(self, value=0.0, text=None): #make the value failsafe: if value < 0.0: value = 0.0 elif value > 1.0: value = 1.0 self._value = value if text == None: #if no text is specified use the default percentage string: text = str(int(round(100 * value))) + ' %' self._canv.coords(self._rect, 0, 0, self._canv.winfo_width()*value, self._canv.winfo_height()) self._canv.itemconfigure(self._text, text=text) self._canv.update_idletasks() def _demo(meter, value): meter.set(value) if value < 1.0: value = value + 0.005 meter.after(50, lambda: _demo(meter, value)) else: meter.set(value, 'TM completed - Please close this window') # this is where progress bar is loaded and where I have added my own stuff def test(): if __name__ == '__main__': root2 = Tkinter.Tk(className=' Text Mining Progress') m = Meter(root2, relief='ridge', bd=3) m.pack(fill='x') i=0.0 for fileid in reader.fileids(): m.set(i, 'Processing will take a few minutes...') i=i+1.000/len(reader.fileids()) # here I increment the colored bar in each iteration m.after(1000, lambda: _demo(m, i)) print str(fileid)[:-4],document_features(reader.raw(fileid))# I call some other processes here root2.withdraw() Thanks Tax ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] multiprocessing for nested function
Part of my code includes the following script, which both shows a progress bar (for as long as 'categorize_reports()' is executed) and prints the fileid and the output of the 'document' function; the latter is the one increasing the calculation time (please see my comment). Any ideas on how to use all the cores of my CPU here? ... def categorize_reports(): if __name__ == '__main__': root2 = Tkinter.Tk(className=' Processing Progress') m = Meter(root2, relief='ridge', bd=3) m.pack(fill='x') i=0.0 for fileid in fileids(): m.set(i, 'Processing will take a few minutes...') i=i+1.000/len(fileids()) m.after(1000, lambda: _demo(m, i)) print str(fileid), document(fileid) #this slows down the process root2.withdraw() ... Thanks Tax ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] multiprocessing for nested function
I am trying to start multiple instances using a for statement but this is not working. Has anyone tried affinity module? Tax 2011/5/17 Emile van Sebille > On 5/17/2011 7:29 AM tax botsis said... > > Part of my code includes the following script, which both shows a >> progress bar (for as long as 'categorize_reports()' is executed) and >> prints the fileid and the output of the 'document' function; the latter >> is the one increasing the calculation time (please see my comment). Any >> ideas on how to use all the cores of my CPU here? >> > > A python instance lives it life on a single processor. Accessing multiple > cores requires you start multiple python instances. You'd need to > restructure to provide some form of cooperative independent processing. > Pyro, stackless, and twisted come to mind. It looks like > the info at http://wiki.python.org/moin/ParallelProcessing is more up to > date than my memory... > > Emile > > > > >> ... >> def categorize_reports(): >> if __name__ == '__main__': >> root2 = Tkinter.Tk(className=' Processing Progress') >> m = Meter(root2, relief='ridge', bd=3) >> m.pack(fill='x') >> i=0.0 >> for fileid in fileids(): >> m.set(i, 'Processing will take a few minutes...') >> i=i+1.000/len(fileids()) >> m.after(1000, lambda: _demo(m, i)) >> print str(fileid), document(fileid) #this slows down the >> process >> root2.withdraw() >> ... >> >> Thanks >> Tax >> >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor