AssertionError: [101, 1203, 1365, 1137, 8601, 117, 4835, 1104, 1141, 1292, 119, 102, 0, 0, 0, 0, 0, 0, 0, 0] is not <class 'list'>

AssertionError: [101, 1203, 1365, 1137, 8601, 117, 4835, 1104, 1141, 1292, 119, 102, 0, 0, 0, 0, 0, 0, 0, 0] is not <class 'list'>

即使预处理函数正在返回列表,每次都会引发断言错误

pre = n.preprocess("New York or Mumbai, choose of one these.")
j = []
for i in range(4):
   ##To check the data type
   print("preprocess", type(pre[i]))
   self.assertIs(pre[i], list)

我该如何解决这个错误?

来自documentation

assertIs(first, second, msg=None)
assertIsNot(first, second, msg=None)
Test that first and second are (or are not) the same object.

你的变量 pre[i] 和内置数据类型 list 不是同一个对象(当然如果你不会分配 pre[i] = list 或类似的东西)。您应该使用其他方法进行比较,例如, assertIsInstance.