Mega Code Archive

 
Categories / Python Tutorial / File
 

Exception you are anticipating

try:    filename = 'file.txt'    fobj = open(filename, 'r')    for eachLine in fobj:        print eachLine,    fobj.close() except IOError, e:      print 'file open error:', e