for line in open("myfile txt")print(lineend=""the problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing this is not an issue in simple scriptsbut can be problem for larger applications the with statement allows objects like files to be used in way that ensures they are always cleaned up promptly and correctly with open("myfile txt"as ffor line in fprint(lineend=""after the statement is executedthe file is always closedeven if problem was encountered while processing the lines objects whichlike filesprovide predefined clean-up actions will indicate this in their documentation predefined clean-up actions