How to convert a tuple in robot framework into lis

2020-07-28 00:20发布

问题:

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]