when you're reading fileyou'll often want to examine each line of the file you might be looking for certain information in the fileor you might want to modify the text in the file in some way for exampleyou might want to read through file of weather data and work with any line that includes the word sunny in the description of that day' weather in news reportyou might look for any line with the tag and rewrite that line with specific kind of formatting you can use for loop on the file object to examine each line from file one at timefile_reader py filename 'pi_digits txtv with open(filenameas file_objectw for line in file_objectprint(lineat we store the name of the file we're reading from in the variable filename this is common convention when working with files because the variable filename doesn' represent the actual file--it' just string telling python where to find the file--you can easily swap out 'pi_digits txtfor the name of another file you want to work with after we call open()an object representing the file and its contents is stored in the variable file_object we again use the with syntax to let python open and close the file properly to examine the file' contentswe work through each line in the file by looping over the file object when we print each linewe find even more blank lines these blank lines appear because an invisible newline character is at the end of each line in the text file the print statement adds its own newline each time we call itso we end up with two newline characters at the end of each lineone from the file and one from the print statement using rstrip(on each line in the print statement eliminates these extra blank linesfilename 'pi_digits txtwith open(filenameas file_objectfor line in file_objectprint(line rstrip()files and exceptions