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'] ]
我们如何实现这一目标?
您正在将列表列表转换为字符串
+ 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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句