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

skip at pobox.com skip at pobox.com
Sat Dec 1 02:28:27 CET 2007


My candidate:

    def chunker(f, splitter=";"):
        rest = ""
        for line in f:
            line = rest + line
            if splitter in line:
                first, rest = line.split(splitter, 1)
                yield first
            else:
                rest = line
        if rest:
            yield rest

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

Skip


More information about the Chicago mailing list