I am using Iron Python as an added 'for free' tool to test the an API that wrapps comms to some custom hardware so the non-development team can play with the hardware via python.
However I can't work out how to get .NET void func(params object[] args) to map to Python def (*args).
Here is some code to explain.
I have a type that allows injecting a logging callback to format and deal with messages is follows the signature of Console.WriteLine and Debug.WriteLine.
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);
}
}
in my IronPython code
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()
output
Hello '('world',)'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
I would like
Hello 'world'
Array[object]).