wxPython fast and slow

John Posner jjposner at snet.net
Sun Mar 8 09:12:03 EDT 2009


>     def move_panel(self, evt):
>         def gen():
>             for x in range(200):
>                 yield x
>             for x in range(200, 0, -1):
>                 yield x
>         for x in gen():
>             self.square.SetPosition((x, 30))
>             time.sleep(0.005)
> 

I can't help with the performance problem, but you don't really need a generator for your x-values. This works:

def move_panel(self, evt):
    for i in xrange(400):
        x = 200-abs(i-200)
        self.square.SetPosition((x, 30))
        time.sleep(0.005)

The generator *does* make for clearer code, though!

-John




More information about the Python-list mailing list