我正在解析患者访问列表(csv文件)。为了解决这个问题,我有一套自定义的类:Python - TypeError:(函数)只需要2个参数(3给出) - 但我只给了2!
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,otherVariable)时,python拦截并传递 - >(self,self,otherVariable) - 因此有3个参数? – chris
@george是正确的。 – multipleinterfaces