parse/slice/...

Tim Arnold tim.arnold at sas.com
Wed Jan 7 12:42:45 EST 2009


"rcmn" <rcmn73 at gmail.com> wrote in message 
news:51451b8a-6377-45d7-a8c8-54d4cadb2594 at n33g2000pri.googlegroups.com...
> I'm not sure how to call it sorry for the subject description.
>   Here what i'm trying to accomplish.
> the script i'm working on, take a submitted list (for line in file)
> and generate thread for it. unfortunately winxp has a limit of 500
> thread . So I have to parse/slice the file by chunk of 500 and loop
> until the list is done.
> I though i would of done it in no time but i can't get started for
> some reason.
> And i can't find a good way to do it efficiently . Does anyone have
> something similar to this.
>
> thank you

Here's how I work on a list a bunch of items (100 by default) ata time:

def drain_list(tlist,step=None):
            if not step:
                step = 100
            j=0
            for i in range(step,len(tlist), step):
                yield tlist[j:i]
                j = i
            if j < len(tlist):
                yield tlist[j:]

--Tim





More information about the Python-list mailing list