运行以下代码时出现此错误:
'builtin_function_or_method'对象不可迭代
我搜索过stackoverflow,但无法找到我的问题的答案......请帮助我!
def file2matrix(filename):
fr = open(filename)
arrayOLines = fr.readlines()
numberOfLines = len(arrayOLines)
returnMat = zeros((numberOfLines, 3))
classLabelVector = []
index = 0
for line in arrayOLines:
line = line.strip()
listFromLine = line.split('\t')
returnMat[index, :] = listFromLine[0:3]
classLabelVector.append(int(listFromLine[-1]))
index += 1
return returnMat, classLabelVector
这是结果......
>>> datingDataMat,datingLabels = kNN.file2matrix("datingTestSet.txt")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Dennis Yang\PycharmProjects\mlaction\kNN.py", line 28, in file2matrix
for line in arrayOLines:
TypeError: 'builtin_function_or_method' object is not iterable