Search code examples
pythonvariablesscons

SCons problem - dont understand Variables class


I'm working on an SConstruct build file for a project and I'm trying to update from Options to Variables, since Options is being deprecated. I don't understand how to use Variables though. I have 0 python experience which is probably contributing to this.

For example, I have this:

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

But I get an error:

AttributeError: Variables instance has no attribute '__getitem__':

Not sure how this is supposed to work


Solution

  • Typically you would store the variables in your environment for later testing.

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

    Then later you can test:

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