for line in result['errors']:
print line
这将输出:
[ [ 'some text here.....', '23', '3'],
[ 'some text here.....', '244', '4'],
[ 'some text here.....', '344', '5'] ]
现在我正在使用assertTrue并想输出列表:
self.assertTrue(result['result'], 'this is error' + \
', data is incorrect' + str(result['errors']))
这将输出:
AssertionError: this is error, data is incorrect[ [ 'some text here.....', '23', '3'], [ 'some text here.....', '244', '4'], [ 'some text here.....', '344', '5'] ]
我需要输出如下:
AssertionError: this is error, data is incorrect
[ [ 'some text here.....', '23', '3'],
[ 'some text here.....', '244', '4'],
[ 'some text here.....', '344', '5'] ]
我们如何实现这一目标?
答案 0 :(得分:1)
您正在将列表列表转换为字符串
+ str(result['errors'])
因此获得单行,您可以使用“\ n”加入以获得多行
+ '\n'.join(map(str, result['errors']))
例如
>>> a = [[1, 2, 3], [4, 5, 6]]
>>>
>>> a
[[1, 2, 3], [4, 5, 6]]
>>> print a
[[1, 2, 3], [4, 5, 6]]
>>> print str(a)
[[1, 2, 3], [4, 5, 6]]
>>> print '\n'.join(map(str, a))
[1, 2, 3]
[4, 5, 6]