初学Python,编写面向对象程序出现 TypeError: this constructor takes no arguments这样的异常,网上查了很多基本上都是说
__init__这个方法前后的下划线为2个,容易因为疏忽写成1个,就会报这个错,可是我的是通过编译工具PyCharm提示生成的怎么会出现这个问题呢,查了半天也没看出来,最后找了半天发现还是因为疏忽,导致init方法写成int方法,对于这类问题可以参考下这个
https://stackoverflow.com/questions/27017493/python-typeerror-this-constructor-takes-no-arguments
class Entity1: def __init__(self,name,age): self.name = name self.age = age def speak(self): print("name=%s,age=%d"% (self.name, self.age)) def __repr__(self): return '<Person {}>'.format(self.name) e1=Entity1("张三",22) e2=Entity1("李四",25)