課程
/后端開發
/Python
/python進階
TypeError: object() takes no parameters
TypeError:?object()?takes?no?parameters
2015-04-10
源自:python進階 4-5
正在回答
__init__函數寫錯成__int__了
我 這段代碼也出現了TypeError: object() takes no parameters 這樣的問題,能幫我看看么?
import Levenshtein
import pylab
class LabelSet(object):
? ? def __int__(self,labelName):
? ? ? ? self.labelName = labelName
? ? def getLabelName(self):
? ? ? ? return self.labelName
? ? def distance(self,other):
? ? ? ? return Levenshtein.distance(self.labelName,other.labelName)
def compareLabels(labels,precision):
? ? columnLabels = []
? ? for a in labels:
? ? ? ? columnLabels.append(a.getLabelName())
? ? rowLabels = columnLabels[:]
? ? tableVals = []
? ? for a1 in labels:
? ? ? ? row =[]
? ? ? ? for a2 in labels:
? ? ? ? ? ? if a1==a2:
? ? ? ? ? ? ? ? row.append('--')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? distance = a1.distance(a2)
? ? ? ? ? ? ? ? row.append(str(round(distance,precision)))
? ? ? ? tableVals.append(row)
? ? table = pylab.table(rowLabels = rowLabels,
? ? ? ? ? ? ? ? ? ? ? ? colLabels = columnLabels,
? ? ? ? ? ? ? ? ? ? ? ? cellText = tableVals,
? ? ? ? ? ? ? ? ? ? ? ? cellLoc = 'center',
? ? ? ? ? ? ? ? ? ? ? ? loc = 'center',
? ? ? ? ? ? ? ? ? ? ? ? colWidths = [0.2]*len(labels))
? ? table.scale(1,2.5)
? ? pylab.axis('off')
? ? pylab.savefig('distance')
classic = LabelSet('classic')
R = LabelSet('R')
comedy = LabelSet('comedy')
action = LabelSet('action')
dvd = LabelSet('dvd')
owned = LabelSet('owned')
labels=[classic,R,comedy,action,dvd,owned]
compareLabels(labels,3)
qq_鴻語_0
月滿軒尼詩
能否列出問題的代碼?
舉報
學習函數式、模塊和面向對象編程,掌握Python高級程序設計
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-09-22
__init__函數寫錯成__int__了
2015-10-20
我 這段代碼也出現了TypeError: object() takes no parameters 這樣的問題,能幫我看看么?
import Levenshtein
import pylab
class LabelSet(object):
? ? def __int__(self,labelName):
? ? ? ? self.labelName = labelName
? ? def getLabelName(self):
? ? ? ? return self.labelName
? ? def distance(self,other):
? ? ? ? return Levenshtein.distance(self.labelName,other.labelName)
def compareLabels(labels,precision):
? ? columnLabels = []
? ? for a in labels:
? ? ? ? columnLabels.append(a.getLabelName())
? ? rowLabels = columnLabels[:]
? ? tableVals = []
? ? for a1 in labels:
? ? ? ? row =[]
? ? ? ? for a2 in labels:
? ? ? ? ? ? if a1==a2:
? ? ? ? ? ? ? ? row.append('--')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? distance = a1.distance(a2)
? ? ? ? ? ? ? ? row.append(str(round(distance,precision)))
? ? ? ? tableVals.append(row)
? ? table = pylab.table(rowLabels = rowLabels,
? ? ? ? ? ? ? ? ? ? ? ? colLabels = columnLabels,
? ? ? ? ? ? ? ? ? ? ? ? cellText = tableVals,
? ? ? ? ? ? ? ? ? ? ? ? cellLoc = 'center',
? ? ? ? ? ? ? ? ? ? ? ? loc = 'center',
? ? ? ? ? ? ? ? ? ? ? ? colWidths = [0.2]*len(labels))
? ? table.scale(1,2.5)
? ? pylab.axis('off')
? ? pylab.savefig('distance')
classic = LabelSet('classic')
R = LabelSet('R')
comedy = LabelSet('comedy')
action = LabelSet('action')
dvd = LabelSet('dvd')
owned = LabelSet('owned')
labels=[classic,R,comedy,action,dvd,owned]
compareLabels(labels,3)
2015-04-13
能否列出問題的代碼?