M
mark jason
hi
I was trying out some file operations and was trying to open a non
existing file as below
def do_work(filename):
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
print 'failed',e.message
finally:
f.close()
print 'closed'
if __name__=='__main__':
do_work("C:\code\misc.txt") # there is no such file
I am getting an error and a warning
DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
print 'failed',e.message
UnboundLocalError: local variable 'f' referenced before assignment
Is there a way to overcome the DeprecationWarning? I wanted to print
the error message from the IOError.How do I do this?
Also ,what should I do about the UnboundLocalError?
thanks and regards ,
mark
I was trying out some file operations and was trying to open a non
existing file as below
def do_work(filename):
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
print 'failed',e.message
finally:
f.close()
print 'closed'
if __name__=='__main__':
do_work("C:\code\misc.txt") # there is no such file
I am getting an error and a warning
DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
print 'failed',e.message
UnboundLocalError: local variable 'f' referenced before assignment
Is there a way to overcome the DeprecationWarning? I wanted to print
the error message from the IOError.How do I do this?
Also ,what should I do about the UnboundLocalError?
thanks and regards ,
mark