我需要从一个关键字处理几种类型的数据 - 根据定义的数据类型调用另一个必要的关键字.
使用Evaluate type()
对于列表和词典是有用的,但是当我们只有一个没有引号的字符串时失败.如果我添加引号 - 数据将始终定义为字符串 - 即使它在列表或字典中.
例如
${list}= Create List 1 two
${type_list}= Evaluate type(${list})
# returns <type 'list'>
${dict}= Create Dictionary first=1 second=two
${type_dict}= Evaluate type(${dict})
# returns <type 'dict'>
${string}= Set Variable withoutQuotes
${type_string}= Evaluate type(${string})
# FAILS with:
Evaluating expression 'type(withoutQuotes)' failed: NameError: name 'withoutQuotes' is not defined
Run Code Online (Sandbox Code Playgroud)
你能否请一些方法来定义一个不会失败的变量类型?