Opening a Nonexistent File : open « File « Python Tutorial






fsock = open("notthere.txt", "r")          
try: 
    fsock = open("notthere.txt")                 
except IOError:                              
    print "The file does not exist, exiting gracefully" 
print "This line will always print"








12.9.open
12.9.1.Access Modes for File Objects
12.9.2.'r' is the default processing mode
12.9.3.Open a file for reading
12.9.4.Open a file for writing
12.9.5.Opening a Nonexistent File
12.9.6.Opening a File and check its mode
12.9.7.Reading and Writing