-1

每次我调用我的函数时def hello(self,value),我都会收到一个错误:takes exactly 2 arguments (1 given)那我该怎么办?

或者是否有另一种可能性来做到这一点:self.statusitem.setImage_(self.iconsuccess)

编辑:

我的代码的简单表示

Class A:
   func_in_class_B(value)

Class B:
def finishLaunching(self):
   self.statusitem.setImage_(self.icon)
def func_in_class_B(self,value)
   self.statusitem.setImage_(self.iconsuccess)

A类是后台线程,B类是我的主线程,我想操作`self.statusitem.setImage_(self.icon)

4

2 回答 2

3

听起来您没有正确调用 hello 函数。给定以下类定义:

class Widget(object):
    def hello(self, value):
        print("hello: " + str(value))

您可能将其称为静态函数,如下所示:

Widget.hello(10)

这意味着没有小部件类的实例作为第一个参数传递。您需要将 hello 函数设置为静态:

class Widget(object):
    @staticmethod
    def hello(value):
        print("hello: " + str(value))

Widget.hello(10)

或像这样在特定对象上调用它:

widget = Widget()
widget.hello(10)
于 2013-02-04T19:01:00.010 回答
1

这很可能是因为您的 hello 函数不是类成员。在这种情况下,您不需要在方法声明中提供 self ......即,而不是 hello(self,value) 只需说 hello(value)

例如......这个片段工作得很好

def hello(value):
    print 'Say Hello to ' + value

hello('him')

如果不是这种情况,请提供您的代码片段以进一步帮助您。

于 2013-02-04T19:07:22.297 回答