You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Robot Framework:如何确保变量为字典列表(自动转换字典)

解决Robot Framework中${agent}变量格式统一问题

可以通过类型判断+条件赋值的方式实现需求,下面提供两种简洁的写法:

写法一:使用Set Variable If(推荐,更简洁)

利用Set Variable If的三元表达式特性,直接完成判断与赋值:

${agent}=    Set Variable If    ${agent} is instance of dict    [${agent}]    ${agent}

逻辑说明:

  • 当${agent}是字典类型时,将其包裹为列表[${agent}]重新赋值
  • 若${agent}已是字典列表,则直接保留原变量值

写法二:使用Run Keyword If

如果习惯分步逻辑,也可以用Run Keyword If实现:

${agent}=    Run Keyword If    ${agent} is instance of dict    Set Variable    [${agent}]    ELSE    Set Variable    ${agent}

验证示例

  • 初始值为单个字典:${agent}={1:2} → 执行后变为[{1:2}]
  • 初始值为字典列表:${agent}=[{1:2}] → 执行后保持[{1:2}]不变

内容的提问来源于stack exchange,提问作者Arokia Raj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 19:52:34