我正在尝试获取Class对象的长度,MyList的,个人可迭代的,self.it. 2种方法的代码如下所示:
def __init__(self, *args, **kwargs):
if isinstance(args, (list, tuple)):
self.it = args
else:
self.it = kwargs
def __len__(self):
print("len")
return len(self.it)
当代码命中def__len__(self)
时,会产生以下错误 -
TypeError Traceback (most recent call last)
<ipython-input-205-00a18097c81b> in <module>()
1 # test your implementation of MyList
----> 2 test_list(MyList)
C:\Users\User\Desktop\beaver\Python_5_HW\graders\grader36.pyc in test_list(StdntClass)
C:\Users\User\Desktop\beaver\Python_5_HW\graders\grader36.pyc in test_guantlet(x, y, *args)
TypeError: 'MyList' object is not subscriptable
我在StackOverflow上搜索过这个错误,但我无法弄清楚可能出现的问题。我应该做些什么?