【问题标题】:Difference between @ and $ in robot framework机器人框架中@和$的区别
【发布时间】:2019-10-31 20:51:24
【问题描述】:
@{metricList}=    Create List
${tabDictionary}=    Create Dictionary
Log    ${metricList}
LOG    ${tabDictionary}

如果我写@{tabDictionary}= Create Dictionary,它将创建一个数组。 如果我写Log @{metricList} 会抛出错误?

那么@和$有什么区别呢?这是为什么呢?

【问题讨论】:

标签: robotframework


【解决方案1】:

@ 运算符需要一个列表结构(类似于经典编程语言中的数组)。

每当您创建列表或字典时,都会将该变量分配给 $ 变量。

您始终可以使用简单的 $ 变量运算符访问列表变量 (@) 或字典变量 (&)。然而,这将打印变量的全部内容。

要访问列表中的项目或字典中的键/值对,您必须使用其对应的运算符。它看起来像这样:

${list_variable}=    Create List    item1    item2    item3
${dictionary_variable}=    Create Dictionary    key1=value1    key2=value2

这样做会很好:

Log    ${list_variable}
Log    ${dictionary_variable}

但要将其内容作为数据结构访问,您需要这样做:

Log    @{list_variable}[0]    # prints the first item
Log    &{dictionary_variable}[key1]    # prints the value assigned to key1

等等

【讨论】:

    【解决方案2】:

    @ - 用于创建列表, & - 用于创建字典, $ - 用于创建字符串/整数

    @{list_variable}=    Create List    item1    item2    item3
    log ${list_variable}     => when you have to access list, Need to use $ not @
    

    字典类似。

    用于创建和访问变量 - 使用 $

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2017-12-25
      • 2011-11-10
      • 2013-06-08
      • 2018-04-25
      • 1970-01-01
      • 2016-04-26
      相关资源
      最近更新 更多