Hi all,
Would like to hear your approaches on how to parse a large txt file with one single line and writing to another file every block of 180 charaters in a new line.

One way.

f_object = open('filename', 'rb')
while True:
    chunk = f_object.read(180)
    if not chunk: break
    do_something_with(chunk)
f_object.close()

More modern an pythonic.

from functools import partial

with open('filename', 'rb') as f_object:
    for byte in iter(partial(f_object.read, 180), b''):
        # Do stuff with byte
commented: interesting +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.