m3trik
m3trik

Reputation: 333

Python 'called with the wrong argument type' error

I understand why I am getting this error, it's looking for my object as an argument, and receiving a string value. But I'm confused as to what the solution would be?

The following code snippet is simply trying to run this command;

self.buttonGroup.addButton(self.ui.m001)

x number of times:

num = 0
range_ = 10
prefix = "m"

for i in range (range_):
    if num <(range_-1):
        numString = "00"+str(num)
        if (num >9):
            numString = "0"+str(num)

        button = "self.ui."+prefix+numString

        self.buttonGroup.addButton(button)
        num +=1

print self.buttonGroup

Upvotes: 2

Views: 653

Answers (1)

eyllanesc
eyllanesc

Reputation: 244301

The problem is that button is a string, a possible solution is to use getattr.

Change:

button = "self.ui."+prefix+numString

to

button = getattr(self.ui, prefix+numString)

Upvotes: 2

Related Questions