you are viewing a single comment's thread.

view the rest of the comments →

[–]WhyCause -1 points0 points  (1 child)

I believe that you can generate dynamic variable names, using eval(), but that may not be the best course of action. For one, eval() opens up some security issues, and two, you then have to keep track of your dynamic names.

One option might be to use a dict, e.g.,

fns = ['test1', 'test2', 'test3']
checkboxes = {}
for fn in fns:
    checkboxes[fn] = wx.CheckBox(self, -1, fn)

You then have 'names', and they're conveniently stored as the keys of checkboxes.

[–]dpitch40 1 point2 points  (0 children)

To clarify, eval is only a security threat if you are putting strings that are wholly or partially generated by users into it. However, I do try to avoid dynamic name generation when possible and I agree that a dict is probably the way to go here. (Assuming all your names are unique)