How to use the try-finally clause to handle exception in Python?
I have the following code
try:
foo = open ( 'test.txt', 'w' )
foo.write ( "It's a test file to verify try-finally in exception handling!!"
)
print 'try block executed'
How do I rewrite this code to use finally clause?