[Tutor] How to use try and except in this case?

Andreas Perstinger andreas.perstinger at gmx.net
Sun Nov 27 21:38:15 CET 2011

On 2011-11-27 17:58, Mic wrote:
> Say that I want to try and open 10 files. If none of these exists, I want an
> error
> message to appear. But only if NONE of these files exists.
> I know how to handle this with one file. But I don't know how to do that
> with more than one.
> So the program should try and open all 10 files and if, and only if, none
> of the files exists I want en error message to appear.

Use a counter which increments with every existing file. After opening 
all files check if the counter is bigger than 0.

Or, if you need to know which files exist, use a list, append existing 
files to it and check at the end if it's not empty.

Do you need more help?

Bye, Andreas

More information about the Tutor mailing list