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
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
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 contain all the other stuff you want