Hello All,<br><br>I have a question. I'm not sure exactly as how to explain it in any other way then the way I will explain it. So I'm sorry if it's hard to understand exactly what it is I'm trying to do. Maybe not. Anyway. Here goes.<br>
<br>Lets say I have a file that looks like this.<br><br>id,name,desc,test<br>123,abc,testing is fun,yeah baby<br>456,qwe,python makes if funner, yeah baby<br>789,zxc,this is another line in this file, yeah baby<br>...<br>
...<br><br>This file can have an unknown amount of lines in it. It can be 700,400 or even 7,000.<br>I do this to read the file:<br><br>        try:<br>            reader = csv.reader(file(filename, "rb"))<br>            try:<br>
                header = reader.next()<br>                self.buffer = list(reader) # total = len(self.buffer)<br>                self.bufferp= [dict(zip(header,line)) for line in self.buffer]<br>                self.header = header<br>
                #for row in reader:<br>                    #self.buffer.append(row)<br>                    #s,a=[],{}<br>                    <br>                    #for j in range(len(self.buffer[0])):<br>                        #a[self.buffer[0][j]]=row[j]<br>
                    #self.bufferp.append(a)<br>                    #i+=1<br>                #self.total = i-1<br>            except csv.Error, e:<br>                sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))<br>
        except IOError, e:<br>            sys.exit('file %s, IOError: %s' % (filename, e))<br><br>What I am currently doing is looping over this file, performing a function for every line. This function isbeing called from this class __init__(), <br>
<br>def loop_lines(self):<br>        <br>        for k in range(len(self.buffer)): #for every line in csv file<br>            self.line=self.buffer[k]<br>            self.some_function(self.line)<br>            <br>            <br>
Now, for my question. Is it possible for me to thread this scenario somehow?<br><br>So that I can set a variable that says how many lines to work on at the same time?<br><br>lets say 10 lines at a time, once it finishes some it moves on to the next ones that are not in the thread pool or something to that nature. Always making sure that it works on 10 at the same time.<br>
<br>How would I achieve something like this in my program? Can someone please recommend something for me. I would greatly appreciate. My program would appreciate it too, seeing as it will be multi-threaded :) Thank you for your help.<br>
<br clear="all">-Alex Goretoy<br><a href="http://www.alexgoretoy.com">http://www.alexgoretoy.com</a><br><br>