开发者社区> 问答> 正文

使用python关键字,例如dict,list,在机器人框架内键入

a  = {}
if type(a) == dict:
    #read using dictionary keys.
else:
    #treat it as a list

如何将python代码迁移到机器人框架。我试过了

${type_obj}=     Evaluate   type(${a})
${type_bool}=    Evaluate   ${type_obj} == dict 
Run Keyword If   ${type_bool}==1    DictHandler
Run Keyword If   ${type_bool}==0    ListHandler

但这只是因为语法错误而中断,

Evaluating expression '<type 'dict'> == dict' failed: SyntaxError: invalid syntax (<string>, line 1)

问题是,robot将python的dict关键字视为字符串。那么,如何检查机器人内部的变量类型?

展开
收起
祖安文状元 2020-02-23 15:57:20 1114 0
2 条回答
写回答
取消 提交回答
  • ${type_obj}= Evaluate type(${a})

    2020-03-05 20:16:37
    赞同 展开评论 打赏
  • ${type_obj}= Evaluate type(${a}) Run Keyword If 'dict' in '${type_obj}' DictHandler ... ELSE ListHandler

    2020-02-23 15:57:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载