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

Mic o0MB0o at hotmail.se
Sun Nov 27 17:58:11 CET 2011


Mic wrote:

>> class SeatButton(tk.Button):
>>      def __init__(self, master, index):
>>          text = str(index+1)
>>          super(SeatButton, self).__init__(master,
>>                                           text=text, bg=FREE,
>>                                           command=self.clicked)
>>          self.filename = "Germany_France{}.txt".format(index+1)
>>          self.occupied = False
>>          if os.path.exists(self.filename):
>>               self["bg"]=OCCUPIED

>In the above snippet button color and the occupied-flag can get out of 
>sync.
>If a seat is occupied the color is correcly updated to red bot the
>self.occupied remains False.
>A simple fix:

>self.occupied = os.path.exists(self.filename)
>if self.occupied:
    >self["bg"] = OCCUPIED


Thanks!

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.


Thanks for your help guys!






More information about the Tutor mailing list