public bool PythonNet(Parameter parameter) { using (Python.Runtime.Py.GIL()) { using (Python.Runtime.PyScope scope = Python.Runtime.Py.CreateScope()) { StringBuilder statementBuilder = new StringBuilder() .AppendLine("[") .AppendJoin("," + Environment.NewLine, parameter.Statements) .AppendLine("]"); int[] results = scope.Eval <int[]>(statementBuilder.ToString()); return(Assert(results, parameter.Sum)); } } }
public bool PythonNet(Parameter parameter) { using (Python.Runtime.Py.GIL()) { using (Python.Runtime.PyScope scope = Python.Runtime.Py.CreateScope()) { List <int> results = new List <int>(parameter.Statements.Length); foreach (string statement in parameter.Statements) { int result = scope.Eval <int>(statement); results.Add(result); } return(Assert(results, parameter.Sum)); } } }
public bool PythonNet(Parameter parameter) { using (Python.Runtime.Py.GIL()) { using (Python.Runtime.PyScope scope = Python.Runtime.Py.CreateScope()) { scope.Set("n", parameter.Numbers); List <int> results = new List <int>(parameter.Numbers.Length); foreach (int number in parameter.Numbers) { int result = scope.Eval <int>(parameter.Statements[number]); results.Add(result); } return(Assert(results, parameter.Sum)); } } }