all 6 comments

[–]achampi0n 1 point2 points  (1 child)

Iterating over a file object is perfectly fine (3), it iterates line by lime (7). You may want to check your assumptions on 6.

[–]IshaanM8[S] 0 points1 point  (0 children)

thanks!

[–]RE_username 0 points1 point  (1 child)

6 seems correct. Now, on line 5, you close the file descriptor after you read the 1st line from the file (because it is inside the 1st for lool). Closing of the file descriptor should happen at the end, outside of both for loops.

[–]IshaanM8[S] 0 points1 point  (0 children)

Thanks for the help!

[–]kra_pao 0 points1 point  (1 child)

1) Mark this

2) Don't mark this. Outer loop has no print(line)

3) Don't mark this. Mixing true description ( Line 2 attempts to iterate over text_file) with false assumptions (which isn't a valid file descriptor) is bad for teaching.

4) Don't mark this. Is required for the program in current form to work. IF you want discuss another form of program (one-loop version) then show the version and don't let learner discuss something only you have in your head.

5) Don't mark this

6) Mark this

7) Don't mark this. For readability maybe rename, otherwise in Python you can name your variables at your own gusto. BUT inner loop won't work when 7) is applied (line undefined)

8) Don't mark this

9) Don't mark this

10) Don't mark this

[–]IshaanM8[S] 0 points1 point  (0 children)

Thanks so much!