Iron Python을 '무료'도구로 사용하여 일부 사용자 지정 하드웨어와 통신하는 API를 테스트하여 비 개발 팀이 Python을 통해 하드웨어와 호환 될 수 있도록합니다.IronPython의 변수 인수를 사용하여 CLR 메서드를 호출하는 방법
그러나 .NET을 얻는 방법을 알아낼 수는 없습니다. void func(params object[] args)
은 파이썬 def (*args)
에 매핑됩니다.
설명 할 코드가 있습니다.
로깅 콜백을 주입하고 메시지를 처리 할 수있는 유형은 Console.WriteLine 및 Debug.WriteLine의 서명과 같습니다. 내 IronPython의 코드에서
public class Engine
{
Action<string, object[]> _logger;
public void Run()
{
Log("Hello '{0}'", "world");
}
public void SetLog(Action<string, object[]> logger)
{
_logger = logger;
}
void Log(string msg, params object[] args)
{
_logger(msg, args);
}
}
import clr
from System import *
from System.IO import Path
clr.AddReferenceToFileAndPath(Path.GetFullPath(r"MyAssembly.dll"))
from MyNamespace import *
def logger(msg, *args):
print(String.Format(msg, args))
print(String.Format(msg, list(args)))
print(String.Format(msg, [args]))
a=[]
for i in args:
a.append(i)
print(String.Format(msg, a))
e = Engine()
e.SetLog(logger)
e.Run()
출력
Hello '('world',)'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
내가 좋아하는 것
Hello 'world'
가능한 중복 배열] (http://stackoverflow.com/questions/1107789/assigning-a-iron-python-list-to-net-array) –
그 게시물의 중복 있다면 다음 중 자신의 질문을 이해하지 못하거나 또는 나는 그들의 것을 이해하지 못한다. (또는 둘 다 :-) –
@HansPassant에 의해 참조 된 질문은 하드 중복이 아니라 가능한 해결책 중 하나를 암시한다고 생각한다. (나의 대답과 conve를 보라. rsion을'Array [object]'로). –