Probably something like this?
def F(): a, b = 0, 1 while True: yield a a, b = b, a + b def subfib(StartNumber, endNumber): for cur in F(): if cur > endNumber: return if cur >= StartNumber: yield cur def lines(): with open('fibo.txt', 'w') as f: for fib in subfib(2, 400): f.write("{} ".format(fib)) if __name__ == "__main__": lines()If this isn't what you need then you need to be more explicit about what the final file should look like.