which one of these is better?

John Salerno johnjsal at NOSPAMgmail.com
Thu Oct 26 14:09:37 EDT 2006


     def create_sql_script(self):
         try:
             with open('labtables.sql') as sql_script:
                 return sql_script.read()
         except IOError:
             wx.MessageBox('Could not locate the file "labtables.sql"',
                           'File Not Found')


OR


     def create_sql_script(self):
         try:
             f = open('labtables.sql')
             sql_script = f.read()
         except IOError:
             wx.MessageBox('Could not locate the file "labtables.sql"',
                           'File Not Found')
         finally:
             f.close()



Do they both do the same thing?



More information about the Python-list mailing list