Python – TypeError :(函数)只需要2个参数(给定3个) – 但我只
发布时间:2020-12-20 12:42:21 所属栏目:Python 来源:网络整理
导读:我正在解析病人访问列表(csv文件).为了解决这个问题,我有一组自定义的类: class Patient: def __init__(self,Rx,ID): ....class PtController: def __init__(self,openCSVFile): self.dict=DictReader(openCSVFile) self.currentPt = '' .... def initNewPt
我正在解析病人访问列表(csv文件).为了解决这个问题,我有一组自定义的类:
class Patient: def __init__(self,Rx,ID): .... class PtController: def __init__(self,openCSVFile): self.dict=DictReader(openCSVFile) self.currentPt = '' .... def initNewPt(self,row): Rx = row['Prescription'] PatientID = row['PatientID'] self.currentPt = Patient(Rx,PatientID) ... 所以,我正在使用csv.DictReader来处理文件;内置于PtController类中.它会迭代,但要为第一位患者设置值,请执行以下操作: firstRow = self.dict.next() self.initNewPt(self,firstRow) ... 错误: TypeError: initNewPt() takes exactly 2 arguments (3 given) 如果我在调用initNewPt之前打印(firstRow),它会按照预期以字典形式打印行. 使用python2.7,这是我第一次使用对象.思考? 解决方法
您不需要像self.initNewPt(self,firstRow)那样直接传递self,因为Python会自动传递它.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |