错误消息Python中字符串列表的格式

abcde
    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'] ]

我们如何实现这一目标?

Lejlot

您正在将列表列表转换为字符串

+ 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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Python中字符串列表的列表

来自分类Dev

Python中字符串列表的列表

来自分类Dev

Python-解析字符串列表格式的字符串列表

来自分类Dev

将字符串列表正确格式化为python中的日期列表

来自分类Dev

在python中解析字符串列表

来自分类Dev

在python中过滤字符串列表

来自分类Dev

连接Python中的字符串列表

来自分类Dev

遍历 Python 中的字符串列表

来自分类Dev

记录中的字符串列表以CSV格式显示?

来自分类Dev

从Python的字符列表中形成字符串列表

来自分类Dev

字符串列表中的字符串长度python

来自分类Dev

使用Python在字符串列表中查找字符串列表中的项目索引

来自分类Dev

Python从字符串列表中删除字符串列表

来自分类Dev

字符串列表中的频繁出现的Python列表

来自分类Dev

删除字符串列表中重复项类型错误python

来自分类Dev

ComboBox显示错误的字符串列表

来自分类Dev

如何从Python中的字符串列表制作直方图?

来自分类Dev

python中带有字符串列表的列

来自分类Dev

在python中给出了字符串列表

来自分类Dev

在python中展平嵌套的字符串列表

来自分类Dev

在python的字符串列表中替换空格

来自分类Dev

在Python中绘制字符串列表的直方图

来自分类Dev

在python中给出了字符串列表

来自分类Dev

循环遍历python中的字符串列表

来自分类Dev

在python中对包含数字的字符串列表进行排序

来自分类Dev

Python 字符串列表中的 Nan 对象

来自分类Dev

Python列表内的字符串列表

来自分类Dev

将字符串列表转换为指定格式的原始python列表

来自分类Dev

替换字符串列表中的字符串时出现“无重载版本”错误

Related 相关文章

热门标签

归档