Esempio n. 1
0
        public static PythonObject Evaluate(string code, params object[] args)
        {
            PythonObject compilation;

            using (PythonException.Checker)
                compilation = Python.Py_CompileString(code, $"{nameof(PythonTest)}.{nameof(Evaluate)}", Python.Py_eval_input);

            PythonModule     module  = new PythonModule("__main__");
            PythonDictionary globals = module.Dictionary;
            PythonDictionary locals  = new PythonDictionary();

            //locals.Add("clr", PyNetModule.ClrObject);
            locals.Add("args", new PythonTuple(args.Select(a => (PythonObject)ObjectManager.ToPython(a))));

            PythonObject result;

            using (PythonException.Checker)
                result = Python.PyEval_EvalCode(compilation, globals, locals);

            return(result);
        }