从库中计算变量

2024-10-03 19:24:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python库(baru变量),包含以下变量:

from bar_class import *

foo = bar_class()

现在在robot中,我有以下代码:

Variables bar_variables.py

Setup
    ${variable1}=    Set Variable    ${foo}
    ${variable2}=    Set Variable    foo
    ${variable3}=    Evaluate    ${variable2}

变量1具有正确的对象,在执行变量3时,出现以下错误:

Evaluating expression 'foo' failed: NameError: name 'foo' is not defined

如果我在python中尝试同样的方法,它会起作用:

from bar_variables import *

variable2 = 'foo'
variable3 = eval(variable2)

在python中,variable3具有正确的对象,而在robot中它不起作用

机器人版本为:

>pybot --version
Robot Framework 3.0.2 (Python 2.7.13 on win32)

Tags: 对象代码fromimportfoobarrobotvariables
1条回答
网友
1楼 · 发布于 2024-10-03 19:24:18

使用变量文件导入的变量不存在于使用Evaluate运行代码的上下文中。即使在变量文件中定义了foo,由Evaluate运行的代码对该变量一无所知。你知道吗

你在问题中所描述的正是机器人的工作原理。你知道吗

相关问题 更多 >