Syntax for lists of tuples

1,100 views
Skip to first unread message

Curtis Matthews

unread,
Oct 29, 2013, 11:58:00 AM10/29/13
to robotframe...@googlegroups.com
Trying to write a keyword in RF that uses as an argument a list object consisting of tuples for start/end date pairs. What I want to do is iterate over this list, read the tuple values, and input text on a web form. Basically:

Iterate over a list of tuples
    @{tuples}=    Create List    ("10:15","17:00")    ("18:50","20:00")
    :FOR    ${tuple}    IN    @{tuples}
    \    ${starttime}    ${endtime}=    ${tuple}
    \    Input Text    starttime    ${starttime}
    \    Input Text    endtime    ${endtime}

This doesn't work, probably because it thinks each list item is just a string and not a tuple. So how do I fix this? I tried using Convert to List from the Collections library on ${tuple} within the FOR loop, but all it does is split all the character strings into a massive list...

Kevin O.

unread,
Oct 29, 2013, 1:00:34 PM10/29/13
to robotframe...@googlegroups.com
You are treating the arguments to Create List as if they are being evaluated via eval() and it does not work that way.
There are many ways to work with lists.
Here is the cleanest example I can think of based on your post:
    ${time pairs}=    Create List    10:15    17:00    18:50    20:00
    :FOR    ${starttime}    ${endtime}    IN    @{time pairs}
    \    Log    ${starttime}
    \    Log    ${endtime}
Here, the pairs appear in order in a single-dimensional list. RF will take the items out two at a time and put them in starttime and endtime because there are two arguments before the IN.

Curtis Matthews

unread,
Oct 29, 2013, 1:13:04 PM10/29/13
to robotframe...@googlegroups.com
Ah. Yeah, OK, that'll work.

Thanks,
Curtis

Kevin O.

unread,
Oct 29, 2013, 1:35:33 PM10/29/13
to robotframe...@googlegroups.com
I'm sorry I hit post before I was done writing that.
Assuming that you had a list of lists and you wanted to work with that without forming a new list, here are two ways to do that...

    ${time range 1}=    Create List    10:15    17:00
    ${time range 2}=    Create List    18:50    20:00
    ${time ranges}=    Create List    ${time range 1}    ${time range 2}
    :FOR    ${time range}    IN    @{time ranges}
    \    ${start}    ${end}=    Set Variable    ${time range}    # get RF to unpack the list
    \    Log    ${start}
    \    Log    ${end}
    \    Log    ${time range[0]}    # start - using extended variable syntax to reference first item in list
    \    Log    ${time range[1]}    # end
Reply all
Reply to author
Forward
0 new messages