列表比较列表失败

时间:2018-03-06 17:10:07

标签: python python-3.x robotframework

我从列表格式列表中获取了一些数据,我将与UI中显示的表进行比较。我将UI表数据提取到列表列表中,并比较数据库与UI。这是结果。

KEYWORD Collections . Lists Should Be Equal ${DataFromDB}, ${DataFromUI}
Documentation:  
Fails if given lists are unequal.

Start / End / Elapsed:  20180306 22:33:28.245 / 20180306 22:33:28.245 / 00:00:00.000
22:33:28.245    FAIL    Lists are different:
Index 0: ('3/6/2018', '16', '8', '50.00', '3024', '841', '27.81') != [u'3/6/2018', u'16', u'8', u'50.00', u'3024', u'841', u'27.81']
Index 1: ('3/5/2018', '16', '9', '56.25', '3024', '2114', '69.91') != [u'3/5/2018', u'16', u'9', u'56.25', u'3024', u'2114', u'69.91']
Index 2: ('3/4/2018', '16', '9', '56.25', '3024', '2224', '73.54') != [u'3/4/2018', u'16', u'9', u'56.25', u'3024', u'2224', u'73.54']
Index 3: ('3/3/2018', '16', '9', '56.25', '3024', '2132', '70.5') != [u'3/3/2018', u'16', u'9', u'56.25', u'3024', u'2132', u'70.50']
Index 4: ('3/2/2018', '16', '9', '56.25', '3024', '2112', '69.84') != [u'3/2/2018', u'16', u'9', u'56.25', u'3024', u'2112', u'69.84']
Index 5: ('3/1/2018', '16', '9', '56.25', '3024', '2112', '69.84') != [u'3/1/2018', u'16', u'9', u'56.25', u'3024', u'2112', u'69.84']
Index 6: ('2/28/2018', '16', '9', '56.25', '3024', '2112', '69.84') != [u'2/28/2018', u'16', u'9', u'56.25', u'3024', u'2112', u'69.84']
Index 7: ('2/27/2018', '16', '9', '56.25', '3024', '2112', '69.84') != [u'2/27/2018', u'16', u'9', u'56.25', u'3024', u'2112', u'69.84']

虽然价值观相同。但List应该是Equal功能失败..

不确定这是否是由于信件而造成的,' u'在UI列表中。

任何人都能说出可能出现的问题。

编辑:

同样来自RF doc {例如,Python元组和具有相同内容的列表被认为是相同的。}不确定为什么"列表应该是相等的"关键字失败

1 个答案:

答案 0 :(得分:1)

您正在将tuplelist进行比较。将您的第一个()更改为[]即可。

a = ['3/6/2018', '16', '8', '50.00', '3024', '841', '27.81']
b = [u'3/6/2018', u'16', u'8', u'50.00', u'3024', u'841', u'27.81']
a1 = ('3/6/2018', '16', '8', '50.00', '3024', '841', '27.81')
print('List to list: ',a == b)
print('Tuple to list:',a1 == b) #your current tuple to list comparison  

输出:

List to list:  True
Tuple to list: False

注意

  

how to convert tuple to list

如果这个('3/6/2018', '16', '8', '50.00', '3024', '841', '27.81')是您的参赛作品,那么只需将其传递给list()函数即可 - 它会处理它。以下是more examples