我必须构建一个将在另一个python文件中使用的类
到目前为止,我的课看起来像这样:
import csv
class HWReader():
def __init__(self, load_data):
self.load_data = open(load_data, 'r')
self.filter = " "
self.threshold = 0
self.logic = " "
self.specific = " "
self.reader = " "
def read_file(self):
self.reader = csv.DictReader(self.load_data, delimiter = ',')
return self.reader
def get_saps(self, record_name):
search_for = [record_name]
for row in self.reader:
if row[0] in search_for:
print(row['RecordID'], row['SAPS-I'])
每当我尝试在测试文件上测试代码时,我得到的错误都是:
File "c:\Users\natv\Documents\LEARNING PROGRAMMING\example4\example4.py", line 29
^
SyntaxError: unexpected EOF while parsing
我尝试仅使用不带for循环的示例代码,但仍然遇到相同的错误。
import csv
class HWReader():
def __init__(self, load_data):
self.load_data = load_data
self.filter = " "
self.threshold = 0
self.logic = " "
self.specific = " "
self.reader = " "
def read_file(self):
file = open(self.load_data)
file2 = csv.DictReader(file, delimiter = ',')
for row in file2:
return (row['RecordID'], row['SAPS-I'])
我检查了第29行,那里没有写任何东西,所以我很困惑为什么存在语法错误。
我是python的新手,对此感到有些困惑,我们将不胜感激。