[Python-ideas] For-loop variable scope: simultaneous possession and ingestion of cake

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 4 12:41:44 CEST 2008


Arnaud Delobelle wrote:

> Isn't this better as:
> 
>     buttons.append(Button(title, getattr(game, action)))
> 
> Unless you want late binding of 'game',

Well, you might, for example if you implement restoring a
saved game by unpickling a Game object and assigning it
to game.

There's always some way to rearrange it so that it works,
but the point is that it's easy to write things like this
that don't work, unless you really keep your wits about
you.

-- 
Greg



More information about the Python-ideas mailing list