[Tutor] How to handle try and except in this case

Mic o0MB0o at hotmail.se
Tue Nov 29 16:16:26 CET 2011


>Could you explain what's unclear about it?  Andreas couldn't get more 
>specific, since you didn't say how these 10 names are provided.


Yes, it was probably my fault. Sorry about that. I have come up with a new 
way of working around
a problem in my main program so I only need two files to be tested if they 
exist instead of say 10 files.

So, the program should check if two text files exist. If neither of them 
exist, and only if neither of them,
then the program should print say "hi".

If only one of them exist, the program should continue to run without 
crashing.


I hope this was more easy to understand!



>> I thought I could co along those lines earlier
>>
>> try:
>>    text_file=open("Hey","r") and text_file1=open("Hey","r")

>Unfortunately this isn't valid Python syntax.  The equal sign has a 
>specific statement syntax, and the only time you can have more than one of 
>them in one statement, is the chained assignments, where they all get bound 
>to the same object.  You wouldn't want to do this anyway, since it would 
>leave all those open files in an unspecified state.

Thanks for the information. I figured that it was a little strange what I 
wrote.


Mic




More information about the Tutor mailing list