Dynamic Object Assignments

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.

Keith Bolton

Keith,

I have a bunch of questions for you.

First off, why do you have the elements of the list inside
parentheses? They should not be, it seems to me.

Second off, the exact error you're getting is just what it says:
you're trying to assign a value to an operator. What do you intend the
line "b%s = wx.Button(self,-1,'') % bindex" to do? It doesn't mean
anything in Python.

b%s means "b mod s" which means, "the remainder of b divided by s".
This statement should never be on the left side of an assignment,
since you can't assign a value to the result of a mod operation.

Peace
Bill Mill
bill.mill at gmail.com

···

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.

Keith Bolton

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org