> New to python.... I have a large file that I need to break up into
> multiple smaller files. I need to break the large file into sections
> where there are 65535 lines and then write those sections to seperate
> files.

If your lines are variable-length, then look at itertools recipes.

from itertools import izip_longest

def grouper(n, iterable, fillvalue=None):
    "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
    args = [iter(iterable)] * n
    return izip_longest(fillvalue=fillvalue, *args)

with open("/file","r") as f:
    for lines in grouper(65535,f,""):
        data_to_write = '\n'.join(lines).rstrip("\n")
        ...
        <write data where you need it here>
        ...

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to