variable name using a for

Sean Ross sross at connectmail.carleton.ca
Tue Mar 2 14:46:07 EST 2004


"Alex" <alx5962NOSPAN at yahoo.com> wrote in message
news:4044e177$0$24960$626a14ce at news.free.fr...
[snip]
> so in my code:
> for x in range(nbSujets):
>   self.button1 = xbmcgui.ControlButton(50, 100, 40, 30, "B"+str(x) )
>   self.addControl(self.button1)

for x in range(nbSujets):
    button_name = "button%d"%x
    setattr(self, button_name, xbmcgui.ControlButton(50, 100, 40, 30,
"B%d"%x ))
    self.addControl(getattr(self, button_name))







More information about the Python-list mailing list