open function fail after running a day
Vinay Sajip
vinay_sajip at yahoo.co.uk
Thu Jun 7 14:27:19 EDT 2007
Try the following (Python 2.5.x):
import logging
t=open(filename,'rb')
try:
data=t.read()
#processing data...
except:
logging.exception("Failed to process %r", filename)
finally:
t.close()
For earlier versions of Python, you will need to nest the try blocks:
import logging
t=open(filename,'rb')
try:
try:
data=t.read()
#processing data...
except:
logging.exception("Failed to process %r", filename)
finally:
t.close()
Regards,
Vinay Sajip
More information about the Python-list
mailing list