python中元类的TypeError

时间:2017-01-16 12:21:03

标签: python python-2.7

我写了以下程序,但它没有用。它有什么问题?

public function tasks()
{
    return $this->hasMany('App\Task');
}

运行时的错误是:

def h(self):
    print "Hello World"
if __name__ == '__main__':
    hello = type('HelloThread', bases=(threading.Thread,object), dict=dict(hello=h))

我的python版本是python2.7

1 个答案:

答案 0 :(得分:3)

错误明确指出type.__init__() takes no keyword arguments,因此在发起type时不要使用关键字参数:

hello = type('HelloThread', (threading.Thread, object), dict(hello=h))