reading files run the example program printfile pyshown below'''quick illustration of reading file (needs revisedfile py run first to create sample txt''infile open('sample txt'' 'contents infile read(print(contentsnow you have come full circlewhat one python program has written into the file sample txtanother has read and displayed in the first line of the program an operating system file (sample txtis associated again with python variable name (infilethe second parameter again gives the mode of operationbut this time it is ' 'short for read this filesample txtshould already existand the intention is to read from it this is the most common mode for fileso the 'rparameter is actually optional the read method returns all the file' data as single stringhere assigned to the variable contents using the close method is generally optional with files being read there is nothing to lose if program ends without closing file that was being read notethere are three related but distinct concepts related to files beginners often get confused and try to merge several in their head or substitute one for another the file name is string that identifies the file in your computer' file system you need the file name to open file creating file objectbut the file object (that tend to call infile or outfileis not the same as the name of the file on your hard drive you assign it to variable name just for use inside your program there is still one more step to the most important partthe contents of the file the read method for file object reads and returns existing contentwhile the write method writes new content into the file there are other methods to read just parts of files (that you can look up in the python documentation)but for this tutorialreading the whole file with the read method is sufficient printupper exercise make the following programs in sequence be sure to save the programs in the same directory as where you start the idle shortcut and where you have all the sample text files printupper pyread the contents of the sample txt file and print the contents out in upper case (this should use file operations and should work no matter what the contents are in sample txt do not assume the particular string written by nextfile py! fileupper pyprompt the user for file nameread and print the contents of the requested file in upper case copyfileupper pymodify fileupper py to write the upper case contents string to new file rather than printing it have the name of the new file be dynamically derived from the old name by prepending 'upperto the name for exampleif the user specified the file sample txt (from above)the program would create file uppersample txtcontaining 'my first output file!when the user specifies the file name stuff txtthe resulting file would be named upperstuff txt iffor some reasonyou want to reread this same file while the same program is runningyou need to close it and reopen it objects and methods