Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SCons if/then语句_Python_Json_Scons - Fatal编程技术网

Python SCons if/then语句

Python SCons if/then语句,python,json,scons,Python,Json,Scons,我在顶级目录中有一个SConscript文件,并且有许多子目录,其中包含包含不同键/值对的JSON文件。我的SConscript文件中有一个env.Command(),我希望根据特定键的值调用它。在Scons中,最好的方法是什么 我的想法是: env.Command( test = Value(params['json_key']) if test == "True": target = out.txt, source = in.txt,

我在顶级目录中有一个SConscript文件,并且有许多子目录,其中包含包含不同键/值对的JSON文件。我的SConscript文件中有一个
env.Command()
,我希望根据特定键的值调用它。在Scons中,最好的方法是什么

我的想法是:

env.Command(
    test = Value(params['json_key'])
    if test == "True":
        target = out.txt,
        source = in.txt,
        action = 'function $SOURCE $TARGET'
    else:
        pass
    )

这是Python,您不能将if/else放在类似的内容中。但是,您可以使用字典将参数传递给
env.Command

if Value(params['json_key']) == "True":
    kw = {
        'target': 'out.txt',
        'source': 'in.txt',
        'action': 'function $SOURCE $TARGET',
    }
else:
    kw = {}
env.Command(**kw)