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

David Terrell dbt at meat.net
Sat Dec 1 13:59:18 CET 2007


On Fri, Nov 30, 2007 at 07:28:27PM -0600, skip at pobox.com wrote:
> 
> My candidate:
> 
>     deft chunker(f, splitter=";"):
>         rest = ""
>         for line in f:
>             line = rest + line
>             if splitter in line:
>                 first, rest = line.split(splitter, 1)

scanning the string twice?

>                 yield first

Bug: doesn't work if there are multiple statements on one line.

>             else:
>                 rest = line
>         if rest:
>             yield rest
> 
>     if __name__ == "__main__":
>         import sys
>         for chunk in chunker(open(sys.argv[1]), ';'):
>             print repr(chunk)

-- 
David Terrell
dbt at meat.net
((meatspace)) http://meat.net/


More information about the Chicago mailing list