line = ''
while True:
    word, space, line = line.partition(' ')
if space:
    yield word
else:
    next_chunk = input_file.read(1000)
if next_chunk:
    line = word + next_chunk
else:
    yield word.rstrip('\n')
return
Iterate through words of a file in Python