Handling I/O Errors : File IO Exception « File « Python






Handling I/O Errors

# shows how to safely open and read from a file and gracefully handle errors.

try:                                          
   fsock = open(filename, "rb", 0)             
   try: 
       fsock.seek(-128, 2)                     
       tagdata = fsock.read(128)               
   finally:                                    
       fsock.close() 
except IOError:                                
    pass 


           
       








Related examples in the same category