TyperError:object()不带参数

时间:2018-07-22 23:37:22

标签: python error-handling

这是我的课:

    class Person:

    def __new__(cls, first, last):
        print("Calling __new__() method of class {}".format(cls))
        return object.__new__(cls, first, last)

    def __init__(self, first, last):
        """Constructor of Person working instance
        (attribute initialization)"""
        print("Calling __init__()")
        self.first = first
        self.last = last
        self.age = 23
        self.residency = "Lyon"

    def __repr__(self):
        return "Person : {} {} aged {} years living in {}".format(self.first, self.last, self.age, self.residency)

person = Person("Doe", "John")
print(person)

,并且出现以下我似乎无法解决的错误:

Calling __new__() method of class <class '__main__.Person'>
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    person = Person("Doe", "John")
  File "test.py", line 6, in __new__
    return object.__new__(cls, first, last)
TypeError: object() takes no parameters

我在做什么错? 谢谢您的欢呼!

1 个答案:

答案 0 :(得分:1)

function querySelectorInArray(nodeArray, selectors) { return nodeArray.filter(function(node) { return node.matches(selectors); }); } 构造函数不需要其他参数。 object方法的正确实现不应传递最后两个参数:

__new__