如何将机器人框架中的元组转换为列表 [英] How to convert a tuple in robot framework into list

查看:66
本文介绍了如何将机器人框架中的元组转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行mysql查询后,得到robot框架中元组形式的结果.

After executing a mysql query, got the results in the form of tuple in robot framework.

为了进行进一步的操作,我需要将该元组转换为列表.

In order to do further operations, I would need to convert that tuple into list.

例如:

@{id}=    Query    select column1 from table_name where column2 = '${var1}' and column = '${var2}'

这里@{id} 将作为元组返回.

Here the @{id} would be returned as a tuple.

前:

( (1), (4) )

现在我需要将上面的元组转换成如下列表:

Now I need to convert the above tuple into list as below :

[ 1, 4 ]

推荐答案

如果你只有一个元组,你可以使用 Convert To List 或 Create List.但是这里有一个元组元组.我认为从列中提取值并创建列表的最干净的方法如下:

If you only had a tuple, you could use Convert To List or Create List. But here you have a tuple of tuples. I think the most clean way to extract the values from a column and create a list is as follows:

${column 1}    Evaluate    [x[0] for x in $id]

如果您的查询有第二列,您可以类似地提取它:

If your query had a second column, you could extract it similarly:

${column 2}    Evaluate    [x[1] for x in $id]

这篇关于如何将机器人框架中的元组转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆