Handle File reading Exception : IO Error : File : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  File   » [  IO Error  ]  Screenshots 
 



Handle File reading Exception




import sys

try:
    f = open('myfile.txt')
    s = f.readline()
    i = int(s.strip())
except IOError, (errno, strerror):
    print "I/O error(%s): %s" (errno, strerror)
except ValueError:
    print "Could not convert data to an integer."
except:
    print "Unexpected error:", sys.exc_info()[0]
    raise

           
       
Related examples in the same category
1.  Define function to Open a file Define function to Open a file
2.  Define file open and read in a function Define file open and read in a function
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.