【发布时间】:2015-01-21 06:29:46
【问题描述】:
这是一个类:
class CoordinateRow(object):
def __init__(self):
self.coordinate_row = []
def add(self, input):
self.coordinate_row.append(input)
def weave(self, other):
result = CoordinateRow()
length = len(self.coordinate_row)
for i in range(min(length, len(other))):
result.add(self.coordinate_row[i])
result.add(other.coordinate_row[i])
return result
这是我的程序的一部分:
def verwerk_regel(regel):
cr = CoordinateRow()
coordinaten = regel.split()
for coordinaat in coordinaten:
verwerkt_coordinaat = verwerk_coordinaat(coordinaat)
cr.add(verwerkt_coordinaat)
cr2 = CoordinateRow()
cr12 = cr.weave(cr2)
print cr12
def verwerk_coordinaat(coordinaat):
coordinaat = coordinaat.split(",")
x = coordinaat[0]
y = coordinaat[1]
nieuw_coordinaat = Coordinate(x)
adjusted_x = nieuw_coordinaat.pas_x_aan()
return str(adjusted_x) + ',' + str(y)
但我在“cr12 = cr.weave(cr2)”处遇到错误:
for i in range(min(length, len(other))):
TypeError: 'CoordinateRow' 类型的对象没有 len()
【问题讨论】:
-
不确定您的问题是什么。您在
CoordinateRow的实例上调用len,但该类没有定义__len__函数。
标签: python list class object typeerror