writing data to files this creates new file called my-new-file txt it then writes three strings to the file each with newline character on the endit then closes the file the effect of this is to create new file called myfile txt with three lines in it using files and with statements like several other types where it is important to shut down resourcesthe file object class implements the context manager protocol and thus can be used with the with statement it is therefore common to write code that will open file using the with as structure thus ensuring that the file will be closed when the block of code is finished withfor examplewith open('my-new-file txt'' 'as flines file readlines(for line in linesprint(lineend='' the fileinput module in some situationsyou may need to read the input from several files in one go you could do this by opening each file independently and then reading the contents and appending that contents to list etc howeverthis is common enough requirement that the fileinput module provides function fileinput input(that can take list of files and treat all the files as single input significantly simplifying this processfor examplewith fileinput input(files=('spam txt''eggs txt')as ffor line in fprocess(line