继承时__init__ 调用__new__报错了
class Programer(object): def __new__(cls, *args, **kwargs): print('call __new__ method') print(args) return super(Programer, cls).__new__(cls, *args, **kwargs) def __init__(self, name, age): print('call __init__ method') self.name = name self.age = age if __name__ == '__main__': programer = Programer('Albert',25) print(programer.__dict__)
运行后会提示
File "E:/autoio_work/python/object/init_new.py", line 13, in __new__ return super(Programer, cls).__new__(cls, *args, **kwargs) TypeError: object() takes no parameters