i need to pass a parameter list stored in a dictionary to a function
implemented by an ironPython class.
I have prepared the minimum example that reproduces the error:
// C# Side
var runtime = Python.CreateRuntime();
dynamic test = runtime.UseFile("test.py");
// Here the parameters dictionary is instantiated and filled
var parametersDictionary = new Dictionary<string, int>();
parametersDictionary.Add("first", 1);
// The Python 'x' instance is called passing parameter dictionary
var result = test.x.ReturnFirstParameter(parametersDictionary);
Now the Python code:
# Python side
# Class 'Expression' definition
class Expression(object):
def ReturnFirstParameter(self, **parameters):
return parameters['first']
# Class 'Expression' instantiation
x = Expression()
When i run the program, i get the following exception:
ReturnFirstParameter() takes exactly 1 argument (2 given)
The first parameter is ‘self’, but it seems like ignoring it receives
2 parameters, ‘self’ and the dictionary.
I have tried changing the dictionary for other parameters and it works well. The problem
only arises when you receive a ** parameter.
I deeply appreciate your help!
Esteban.
It should work to simply remove the
**from in front ofparametersin the Python code:**should be used when you are passing in named parameters to a function, and your C# code will be passing a dictionary.Your C# code would call the function like this:
For it to work with
**parametersthe call would need to beThere may be a way to do this with ironpython but I’m not sure how.