我将一些输出分成一个列表,然后尝试清理列表,因为列表上不需要一些值。我要删除任何不是节点或日期的列表项;但是,从列表中删除值关键字将返回一个空列表。任何建议都将不胜感激。
Create And Clean Times List
@{times} Split String ${output} separator=${\n}
Log List ${times}
${value}= Set Variable @{times}[0]
@{times2}= Remove Values From List ${value}
Log List ${times2}
>
KEYWORD Collections . Log List ${times}
Start / End / Elapsed: 20181012 12:16:32.635 / 20181012 12:16:32.636 /
00:00:00.001
12:16:32.636 INFO List length is 28 and it contains following items:
0: META: ran handlers
1: node1 | SUCCESS | rc=0 >>
2: Fri Oct 12 16:16:29 GMT 2018
3: node2 | SUCCESS | rc=0 >>
4: Fri Oct 12 16:16:29 GMT 2018
5: node3 | SUCCESS | rc=0 >>
6: Fri Oct 12 16:16:29 GMT 2018
7: node4 | SUCCESS | rc=0 >>
8: Fri Oct 12 16:16:29 GMT 2018
9: node5 | SUCCESS | rc=0 >>
10: Fri Oct 12 16:16:29 GMT 2018
11: node6 | SUCCESS | rc=0 >>
12: Fri Oct 12 16:16:30 GMT 2018
13: node7 | SUCCESS | rc=0 >>
14: Fri Oct 12 16:16:31 GMT 2018
15: node8 | SUCCESS | rc=0 >>
16: Fri Oct 12 16:16:31 GMT 2018
17: node9 | SUCCESS | rc=0 >>
18: Fri Oct 12 16:16:31 GMT 2018
19: node10 | SUCCESS | rc=0 >>
20: Fri Oct 12 16:16:31 GMT 2018
21: node11 | SUCCESS | rc=0 >>
22: Fri Oct 12 16:16:31 GMT 2018
23: node12 | SUCCESS | rc=0 >>
24: Fri Oct 12 16:16:32 GMT 2018
25: META: ran handlers
26: META: ran handlers
27: [sysadmin@basebox ~]$
00:00:00.001KEYWORD ${value} = BuiltIn . Set Variable @{times}[0]
Start / End / Elapsed: 20181012 12:16:32.637 / 20181012 12:16:32.638 / 00:00:00.001
12:16:32.638 INFO ${value} = META: ran handlers
00:00:00.001KEYWORD @{times2} = Collections . Remove Values From List value='${value}'
Documentation:
Removes all occurrences of given values from list.
Start / End / Elapsed: 20181012 12:16:32.639 / 20181012 12:16:32.640 / 00:00:00.001
12:16:32.640 INFO @{times2} = [ ]
Start / End / Elapsed: 20181012 12:16:32.640 / 20181012 12:16:32.641 / 00:00:00.001
00:00:00.001KEYWORD Collections . Log List ${times2}
Documentation:
Logs the length and contents of the list using given level.
Start / End / Elapsed: 20181012 12:16:32.642 / 20181012 12:16:32.643 / 00:00:00.001
12:16:32.643 INFO List is empty.
答案 0 :(得分:3)
Remove values from list
不返回新列表,而是从原始列表中删除值。
这是一个说明情况的测试:
*** Settings ***
Library Collections
*** Variables ***
@{full_list} one two three
@{short_list} one three
*** Test Cases ***
Example
${result}= remove values from list ${full_list} two
should be equal ${result} ${NONE}
should be equal ${full_list} ${short_list}