Re: with statements and exceptions

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > def create_sql_script(self): > with open('labtables.sql') as sql_script: > return sql_script.read() > > Does the file still get closed even though I have a return statement > inside the with block? Yes, I think so. I'm not run

Re: with statements and exceptions

2006-10-25 Thread John Salerno
John Salerno wrote: > I'm thinking about using a with statement for opening a file, instead of > the usual try/except block, but I don't understand where you handle an > exception if the file doesn't open. For example: > > with open('myfile', 'r'): > BLOCK > > I assume that BLOCK can/will c