书友
2018-10-22 18:23
#!/usr/bin/ipython
#coding:utf-8
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__
def __new__(cls,*args,**kwargs):
print ("call __new__ method")
print (args)
return super(Programer,cls).__new__(cls,*args,**kwargs)
去掉括号里的*args,**kwargs 再运行就好了
class Programer: def __new__(cls, *args, **kwargs): print("call __new__ method") print(args) return super(Programer, cls).__new__(cls) 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__)
你可以把报错情况给贴出来
Python-面向对象
71233 学习 · 81 问题
相似问题