Reputation: 11
I need help with this error: "AttributeError: 'builtin_function_or_method' object has no attribute 'split' 2""
import operator
from numpy import *
def loadDataSet(filename):
dataMat= []; labelMat= []
fr = open(filename)
for line in fr.readlines():
lineArr = line.strip.split('\t')
dataMat.append([float(lineArr[0]), float(lineArr[1])])
labelMat.append(float(lineArr[2]))
return dataMat, labelMat
def selectJrand(i, m):
j=i
while (j == i):
j=int(random.uniform(0, m))
return j
def clipAlpha(aj, H, L):
if aj > H:
aj=H
if L > aj:
aj = L
return aj
The bug as follows:
dataArr, labelArr = svmMLiA.loadDataSet('testSet.txt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\python2.7.12\lib\svmMLiA.py", line 5, in loadDataSet
lineArr = line.strip.split('\t')
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Upvotes: 0
Views: 27566
Reputation: 2096
Note strip
is a class method, to call it, you have to use strip()
. Just fix you code next way:
lineArr = line.strip().split('\t')
To get more information, read docs.
Upvotes: 2
Reputation: 599590
As the error says, strip
is a method that you need to call, just like split
.
lineArr = line.strip().split('\t')
Upvotes: 1