file.open() ending up with an infinite loop

  break, python-3.x

I have a small doubt about an online assignment of mine that I completed. So the assignment requires me to open a txt file and make all the characters upper case.

fh = open(f)
fhand=fh.read()
for line in fhand:
    line=fhand.rstrip()
    line=fhand.upper()
    print(line)
    break

this is the code that I used. If I don’t add the break statement, I’m ending up with an infinite loop. Can anyone explain why this is so?

Source: Python-3x Questions

LEAVE A COMMENT