Ejemplo n.º 1
0
        public static PythonModule Build(string code, params object[] args)
        {
            PythonObject compilation;

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

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

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

            using (PythonException.Checker)
                Python.PyImport_ExecCodeModule(module.Name, compilation);

            return(module);
        }