in reply to Re: Output from read/write txt file
in thread Output from read/write txt file

It needs to be outside of the loop because of the way I read input into the program and it's looping through line by line? Or if not, can you explain why it needs to be outside of the loop? Thanks!

Replies are listed 'Best First'.
Re^3: Output from read/write txt file
by toolic (Bishop) on Mar 12, 2015 at 15:34 UTC
    It needs to be outside of the loop because of the way I read input into the program and it's looping through line by line?
    Yes.

    If you have any further questions, post a small sample of your input file and the exact output you desire.

      Once I put my print statement outside of the loops I am getting the output I desire. Thanks again!
Re^3: Output from read/write txt file
by AppleFritter (Vicar) on Mar 12, 2015 at 21:14 UTC

    Yes. It needs to be outside the loop because your loop's going through the input file line by line. Everything that's inside the loop is done for each individual line, so if you print to your output file inside the loop, you'll print to it for every single individual line of your input file.

    Move the print statement out of the loop, and it'll only execute once, after the loop is done and the entire input file has been read and processed.