Why does this code crash python?

Martin Blume mblume at socha.net
Sun Nov 12 07:40:58 EST 2006


<Mythmon at gmail.com> schrieb 
> I am trying to make a program that will basically simulate 
> a chess clock in python. ...
> ... it crashes shortly after. 

Can't help you on why it crashes, but

> 
> class eventMonitor (Thread):
>     def run ( self ):
>         [snipped]
>                     if event.keycode == 32:
>                         if turn == 1: turn = 0
>                         if turn == 0: turn = 1
>

looks wrong to me. This is supposed to switch between the 
players (0 and 1), but the first if changes turn to 0, the
second changes it immediately back to 1.

I'd do:
  if turn == 1:  turn = 0
  else:          turn = 1

HTH
Martin





More information about the Python-list mailing list