无论如何,是否将存储在变量中的值用作搜 索类的另一个变量的键?

问题描述 投票:-1回答:1

[目前,我正在与Jenkins集成一个硒项目。我已经将Locators存储在一个类中。因此,我的目标是从jenkins中获取输入,并使用该变量作为从

中获取值的键。
class Locators(object):
    rundate = 'PREV' # This value is user input, either PREV or NOW
    PREV = 'abcd'
    NOW  = 'bcd'

所以我想将其用作:

Test = Locators() Test.(Test.rundate)

python class variables jenkins
1个回答
0
投票

点分属性访问始终需要属性名称的有效标识符,而不是任意表达式。在其他情况下,请使用getattr

getattr(Test, Test.rundate)
© www.soinside.com 2019 - 2024. All rights reserved.