Dynamic Object Assignments

So, you were hoping that the "% cindex" operator would modify the left side of the assignment operator? I think you need to do a bit more reading. "%" only operates on strings, not on statements.

You should be using a dictionary or a list for this. That's what they was designed for. For example:

  b = {}
  c = {}
  t = {}
  for item in List:
    if item == 'button':
      b[bindex] = wx.Button(self,-1,'')
      bindex += 1
    elif item == 'textctrl':
      t[tindex] = wx.TextCtrl(self,-1,'')
      tindex += 1
    else:
      c[cindex] = wx.CheckBox(self,-1,'')
      cindex += 1

Or, if you really want the indexes to be sequential, this is even easier:

  b =
  c =
  t =
  for item in List:
    if item == 'button':
      b.append( wx.Button(self,-1,'') )
    elif item == 'textctrl':
      t.append( wx.TextCtrl(self,-1,'') )
    else:
      c.append( wx.CheckBox(self,-1,'') )

···

On Tue, 02 Nov 2004 17:39:20 -0800, "Keith Bolton" <Keith.Bolton@batescapital.com> wrote:

I am trying to create wx objects dynamically, for example:

List = [(button),(textctrl),(button),(checkbox)]

bindex,tindex,cindex = 1

for item in List:
   if item == 'button':
       b%s = wx.Button(self,-1,'') % bindex
       bindex += 1

   elif item == 'textctrl':
       t%s = wx.TextCtrl(self,-1,'') % tindex
       tindex += 1

   else:
       c%s = wx.CheckBox(self,-1) % cindex
       cindex += 1

I get "SyntaxError: can't assign to operator". Maybe you know what I'm
trying to do is possible, thanks for any hints.

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.