How to convert a tuple in robot framework into list

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 19:31:54

问题


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.

Ex:

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

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

EX :

( (1), (4) )

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

[ 1, 4 ]

回答1:


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]


来源:https://stackoverflow.com/questions/35511116/how-to-convert-a-tuple-in-robot-framework-into-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!