【问题标题】:SCons problem - dont understand Variables classSCons 问题 - 不理解变量类
【发布时间】:2009-01-18 23:13:16
【问题描述】:

我正在为一个项目编写 SConstruct 构建文件,并且我正在尝试从选项更新为变量,因为选项已被弃用。我不明白如何使用变量。我有 0 次 python 经验,这可能是造成这种情况的原因。

例如,我有这个:

opts = Variables()
opts.Add('fcgi',0)
print opts['fcgi']

但我得到一个错误:

AttributeError: Variables instance has no attribute '__getitem__':

不确定这应该如何工作

【问题讨论】:

  • 对于像我一样在这里完全困惑的人的注意事项:您必须 Add() 变量才能真正从文件中读取它们。您不能只是将内容添加到文件中并期望它们显示在您的 opts 中。

标签: python variables scons


【解决方案1】:

通常您会将变量存储在您的环境中以供以后测试。

opts = Variables()
opts.Add('fcgi',0)
env = Environment(variables=opts, ...)

然后你就可以测试了:

if env['fcgi'] == 0:
    # do something

【讨论】:

    【解决方案2】:

    该特定错误告诉您 Variables 类尚未实现 python 的 __getitem__ interface,这将允许您在 opts 上使用 [ ...]。如果您只想打印出您的密钥,Variables documentation 似乎表明您可以遍历您的密钥:

    for key in opts.keys():
        print key
    

    或者您可以打印出帮助文本:

    print opts.GenerateHelpText()
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多