def bjamToPy( funcName, splitRules ): assert( len( splitRules ) != 0 ) invocation = funcName + "(" argc = 0 argNames = "" for splitRule in splitRules: name = "arg" + str(argc) argc += 1 argNames += name + "," splitc = 0 for split in splitRule: # If we have more than one element create a list if ( split > 1 ): invocation += "[" # Write arg[0], arg[1], ..., arg[ splitc - 1 ] for pyArg in range( splitc, splitc + split ): invocation += name + "[" + str(pyArg) + "]," splitc += split # If we have more than one element close list if ( split > 1 ): invocation = invocation[:-1] + "]," # Special case - take everything left in this parameter if ( split == 0 ): invocation += name + "[" + str(splitc) + ":]," break # Remove trailing ',' argNames = argNames[:-1] invocation = invocation[:-1] + ")" return eval( "lambda " + argNames + ":" + invocation ) def flags( ruleOrModule, varName, condition, someOtherParam ): print "----------------------------" print "RuleOrModule: ", ruleOrModule print "VarName: " , varName print "Condition" , condition print "SomeOtherParam", someOtherParam flagsBjam = bjamToPy( "flags", [ [1,1,0], [0] ] ) #test1 flagsBjam( [ 'ruleOrModuleVar', 'variableVar', 'condition1Var', 'condition2Var'], ['SomeOtherParam'] ) #test2 flagsBjam( [ 'ruleOrModuleVar', 'variableVar'], ['SomeOtherParam'] )