Пример #1
0
        public static void RunScriptPython(string pythonContent, object[] inputObj)
        {
            ScriptEngine _engine = Python.CreateEngine();

            #region 字符串
            var code = @"import sys" + "\n" +
                       @"import clr" + "\n" +
                       @"sys.path.append("".\pythonlib.zip"")" + "\n" +
                       @"sys.stdout=my" + "\n" +
                       @pythonContent;
            var source = _engine.CreateScriptSourceFromString(code);

            var scope = _engine.CreateScope();
            scope.SetVariable("my", new Test());
            source.Execute(scope);
            #endregion

            var main = scope.GetVariable <Func <object[], string> >("start");

            var s = main(inputObj);

            OutWriteHandler?.Invoke("返回结果:" + s);
        }
Пример #2
0
 public void write(string s)
 {
     OutWriteHandler?.Invoke(s);
 }