[Tutor] Help with excetion handing and making my code more efficient needed please
rabidpoobear at gmail.com
Sat May 19 00:03:16 CEST 2007
Matt Smith wrote:
> On Fri, 2007-05-18 at 23:49 +0200, Rikard Bosnjakovic wrote:
>> Something like this:
>> except IndexError:
> Thanks Rikard,
> I'm not sure how I would go about actually suppressing the error - what
> would suppress_the_error() actually call?
In this case, you don't need to do anything to the error.
You're expecting an IndexError, and if one occurs, you're assuming that
that neighbor doesn't count.
So just put the code Rikard sent you in the try block
and in the except block, put 'pass' (i.e. "Do Nothing").
Another note: I think (x-1, x, x+1) is more clear than (x, x+1, x-1),
and also: note that Rikard's code will always check x,y which will
always be 1 (assuming you don't do checks on
whether they should stay alive for already dead squares!)
You can add an if statement to remove this case, or, easier (and
probably more efficient) just subtract 1 from your result.
More information about the Tutor