I'm parsing a list of patient visits (csv file). To deal with this, I have a custom set of classes:
我正在解析一个病人访问列表(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)
...
So, I'm using the csv.DictReader to process the file; built into the PtController class. It iterates through, but to set values for the first patient does the following:
我用的是csv。对文件进行处理;内置到PtController类中。它遍历,但为第一个病人设置值如下:
firstRow = self.dict.next()
self.initNewPt(self,firstRow)
...
The error:
错误:
TypeError: initNewPt() takes exactly 2 arguments (3 given)
If I print(firstRow) before calling initNewPt, it prints the row in dictionary form as expected.
如果我在调用initNewPt之前打印(firstRow),它会按照预期的方式打印出字典形式的行。
Using python2.7, and this is my first time working with objects. Thoughts?
使用python2.7,这是我第一次使用对象。想法吗?
3 个解决方案
#1
11
You do not need to pass self
directly as in self.initNewPt(self,firstRow)
, since it is automatically passed implicitly by Python.
因为它是由Python自动传递的,所以不需要将self直接传递给self。initnewpt (self,firstRow)。
#2
5
When you call self.initNewPt()
you should not pass self
as a parameter. This is an implied parameter that's automatically present.
当您调用self。initnewpt()时,您不应该将self作为参数传递。这是一个自动出现的隐含参数。
#3
4
You need to call the initNewPt
without the self
argument within a class method:
您需要在类方法中调用initNewPt,而不需要使用self参数:
self.initNewPt(firstRow)
#1
11
You do not need to pass self
directly as in self.initNewPt(self,firstRow)
, since it is automatically passed implicitly by Python.
因为它是由Python自动传递的,所以不需要将self直接传递给self。initnewpt (self,firstRow)。
#2
5
When you call self.initNewPt()
you should not pass self
as a parameter. This is an implied parameter that's automatically present.
当您调用self。initnewpt()时,您不应该将self作为参数传递。这是一个自动出现的隐含参数。
#3
4
You need to call the initNewPt
without the self
argument within a class method:
您需要在类方法中调用initNewPt,而不需要使用self参数:
self.initNewPt(firstRow)