var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
var paths = engine.GetSearchPaths();
/*
paths.Add(@".\python");
paths.Add(@".\python\venv");
paths.Add(@".\python\venv\Lib");
paths.Add(@".\python\venv\Lib\site-packages");
paths.Add(@"D:\OneDrive\2.CREEDSOFT\1.PrintCheckVision\Source\LineTrigger\LineTrigger\Lib");
*/
paths.Add(@"C:\Python27");
paths.Add(@"C:\Python27\DLLs");
paths.Add(@"C:\Python27\Lib");
paths.Add(@"C:\Python27\Lib\site-packages");
engine.SetSearchPaths(paths);
try
{
//var source = engine.CreateScriptSourceFromFile(@".\python\main.py");
var source = engine.CreateScriptSourceFromFile(@".\python\test.py");
source.Execute(scope);
var getPythonFuncResult = scope.GetVariable<Func<string>>("getPythonFunc");
Console.WriteLine("def 실행 테스트 : " + getPythonFuncResult());
var sum = scope.GetVariable<Func<int, int, int> > ("sum");
Console.WriteLine(sum(1, 2));
var test_arry = scope.GetVariable<Func<byte[], IronPython.Runtime.List>>("test_arry");
IronPython.Runtime.List list = new IronPython.Runtime.List();
list = test_arry(new byte[4] { 0, 1, 2, 3 });
}
catch (Exception ex)
{
}
import numpy as np
def getPythonFunc():
return "hello"
def sum(a, b):
c = a + b
return c
def test_arry(test_list):
for i in test_list:
print(i)
rst_arry = []
rst_arry.append("1");
rst_arry.append("2");
rst_arry.append("3");
rst_arry.append("4");
return rst_arry
print("hello iron python")
댓글