RF:将$ {SPACE},$ {EMPTY}和 - 值替换为'0'

时间:2018-03-16 17:28:01

标签: python robotframework

目前正在使用Robot Framework List。 我有一个像这样的列表['Thu 2/22/2018', ' ', '-', '0.0000', '0', '', 'Fri 2/23/2018', '0', '-', '0.0000', '0', '+20 hr 28 min', 'Sat 2/24/2018', '37', '37', '0.0000', '37', '-10 hr 23 min']我想将$ {SPACE},$ {EMPTY}和 - 值转换为'0'。我正在尝试下面的代码,但我收到这些错误

ValueError: Cannot convert index ' ' to an integer.
ValueError: Cannot convert index '-' to an integer.
ValueError: Cannot convert index '' to an integer.

这是代码

:FOR   ${x}  IN   @{OnlyList}
\  Log   ${x}   console=true
\   run keyword if  '${x}'== '${SPACE}'  Collections.set list value  ${OnlyList}  ${x}  0
\   run keyword if  '${x}'== '-'  Collections.set list value  ${OnlyList}  ${x}  0
\   run keyword if  '${x}'== '${EMPTY}'  Collections.set list value  ${OnlyList}  ${x}  0

不确定如何转换。帮助。

1 个答案:

答案 0 :(得分:6)

Set List Value index 作为第二个参数。

${i}    Set Variable    ${0}
:FOR   ${x}  IN   @{OnlyList}
\  Log   ${x}   console=true
\   run keyword if  '${x}'== '${SPACE}'  Collections.set list value  ${OnlyList}  ${i}  0
\   run keyword if  '${x}'== '-'  Collections.set list value  ${OnlyList}  ${i}  0
\   run keyword if  '${x}'== '${EMPTY}'  Collections.set list value  ${OnlyList}  ${i}  0
\   ${i}    Set Variable    ${i+1}
Log   ${OnlyList}   console=true