Re: try/except with multiple files

2007-06-24 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: On Jun 21, 9:00 pm, Robert Hicks [EMAIL PROTECTED] wrote: Is it good practice to do something like: try: f1 = file('file1') f2 = file('file2') except: # catch the exception If what you want is to make sure that resources will be released, you can

Re: try/except with multiple files

2007-06-22 Thread Stargaming
Matimus wrote: It depends, what are you going to do if there is an exception? If you are just going to exit the program, then that works fine. If you are going to just skip that file, then the above wont work. If you are going to return to some other state in your program, but abort the file

try/except with multiple files

2007-06-21 Thread Robert Hicks
Is it good practice to do something like: try: f1 = file('file1') f2 = file('file2') except: # catch the exception Or do you do a try/except for each open? Robert -- http://mail.python.org/mailman/listinfo/python-list

Re: try/except with multiple files

2007-06-21 Thread Matimus
It depends, what are you going to do if there is an exception? If you are just going to exit the program, then that works fine. If you are going to just skip that file, then the above wont work. If you are going to return to some other state in your program, but abort the file opening, you might

Re: try/except with multiple files

2007-06-21 Thread Robert Hicks
On Jun 21, 3:11 pm, Matimus [EMAIL PROTECTED] wrote: It depends, what are you going to do if there is an exception? If you are just going to exit the program, then that works fine. If you are going to just skip that file, then the above wont work. If you are going to return to some other state

Re: try/except with multiple files

2007-06-21 Thread [EMAIL PROTECTED]
On Jun 21, 9:00 pm, Robert Hicks [EMAIL PROTECTED] wrote: Is it good practice to do something like: try: f1 = file('file1') f2 = file('file2') except: # catch the exception It's bad practice. Because you use a bare except clause, and don't do anything useful with the exceptions