files we will primarily focus on reading and writing text files such as those we create in text editor later we will see how to work with database files which are binary filesspecifically designed to be read and written through database software opening files when we want to read or write file (say on your hard drive)we first must open the file opening the file communicates with your operating systemwhich knows where the data for each file is stored when you open fileyou are asking the operating system to find the file by name and make sure the file exists in this examplewe open the file mbox txtwhich should be stored in the same folder that you are in when you start python you can download this file from www py com/code /mbox txt fhand open('mbox txt'print(fhandif the open is successfulthe operating system returns us file handle the file handle is not the actual data contained in the filebut instead it is "handlethat we can use to read the data you are given handle if the requested file exists and you have the proper permissions to read the file open close read write your program from stephen return-path< datesat jan tosource@coll fromstephen subject[sakaidetailshttp:figure file handle if the file does not existopen will fail with traceback and you will not get handle to access the contents of the filefhand open('stuff txt'traceback (most recent call last)file ""line in filenotfounderror[errno no such file or directory'stuff txtlater we will use try and except to deal more gracefully with the situation where we attempt to open file that does not exist