Wednesday 12 July 2017

37 finally block in python

aaa
try:
    sal=open("C:\\Users\\lachu\\Desktop\\sl.txt","r")
    #print(sal.read())
    #sal.seek(0)
    totalsal=0
    for x in sal:   
        totalsal=float(x)+totalsal
except ValueError:
    print("not valid nuber in file")
except IOError:
    print("file not found")
   
finally:
    sal.close()
    #print ("sal is",totalsal)

No comments:

Post a Comment