[Chicago] is there really no built-in file/iter split() thing?

Kumar McMillan kumar.mcmillan at gmail.com
Sat Dec 1 01:12:36 CET 2007


On Nov 30, 2007 5:56 PM, John Hunter <jdh2358 at gmail.com> wrote:
> Could you describe in words what you are trying to do?

I was just curious if anyone knew of a builtin object that accepted a
file and a token (i.e. ';') and yielded each part of that file split
by tokens.  In code:
open('big.sql').read().split(';')
...but instead of reading the whole file at once, streamed for
efficiency.  I posted my implementation then everyone posted
variations on that but I didn't see one using a builtin module or
method designed specifically for this.  So I guess that answers it.

>
> Sent via BlackBerry from T-Mobile
>
>
> -----Original Message-----
> From: "Michael Tobis" <mtobis at gmail.com>
>
> Date: Fri, 30 Nov 2007 16:59:53
> To:"The Chicago Python Users Group" <chicago at python.org>
> Subject: Re: [Chicago] is there really no built-in file/iter split() thing?
>
>
> def chunker(file,splitter=";"):
>    r = c = ""
>    while (c or not r) and (not c == splitter)
>       c = file.read(1)
>       r.append(c)
>    return r
>
> I suspect I'm missing something to make this prettier, but
> file.read(1) seems to be the way to go through a file bytewise.
>
> mt
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>


More information about the Chicago mailing list