Iterate creating variables?

tdahsu at gmail.com tdahsu at gmail.com
Fri Jun 13 18:16:19 CEST 2008


On Jun 13, 12:03 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> > Thank you, this is much closer to where I need to be...
>
> > The issue is (and this is the part that you don't know, because I
> > didn't tell you!) is that I later need to call methods on
> > "self.checkbox1", for instance:
>
> > self.checkbox1.GetValue()
>
> > to determine if the box is checked or not.
>
> > I should have included that piece in the initial problem description;
> > my apologies.
>
> Then translate the above to
>
> self.checkboxes[1].GetValue()
>
> The point of all this is the following: If you have a variable (even if
> not changing often, or being globally configured) number of objects,
> it's a good idea to keep them around in a list.
>
> Even if you need specific parameters for the checkboxes, it would most
> probably be better to do it like this
>
> checkbox_args = [
>    ("name", parameter, ...),
>    ("other_name", other_parameter, ...),
> ]
>
> for parameters in checkbox_args:
>     checkboxes.append(Checbbox(*parameters))
>
> If you know on the other hand that you will have 10 checkboxes which
> have all a defined meaning, it might be better to use a meaningful name
> for them, like:
>
> self.create_backup = Checkbox(...)
> self.perform_authorization = Checkbox(...)

Trying self.checkboxes[1].GetValue(), gives me:

'NoneType' object has no attribute "GetValue"

Thanks.



More information about the Python-list mailing list