コード例 #1
0
        public Dictionary <string, List <double> > CallClassMethod(string className, string method, PythonCallerArgs args)
        {
            results = "";
            errors  = "";
            string argString = args.Serialized();

            //Caller produces the command:
            // path/to/python.exe caller.py path/to/python/module python_module_name class_name method_name args_string
            //caller.py is the aggregator script, which finds the desired script (python_module_name.py), imports its contents and calls the class method
            //args_string is JSON-formatted array of the arguments for the desired script (python_module_name.py)

            psi.Arguments = $"\"{caller}\" \"{scriptPath}\" \"{scriptName}\" \"{className}\" \"{method}\" \"{argString}\"";

            var value     = System.Environment.GetEnvironmentVariable("PATH");
            var new_value = envPath + "\\:" + envPath + "\\Scripts:" + value;

            System.Environment.SetEnvironmentVariable("PATH", new_value);

            using (var process = Process.Start(psi))
            {
                errors  = process.StandardError.ReadToEnd();
                results = process.StandardOutput.ReadToEnd();
            }

            Dictionary <string, List <double> > ob = JsonConvert.DeserializeObject <Dictionary <string, List <double> > >(results);

            return(ob);
        }