0

i want to dynamically assign parameter values coming from a .net's Dictionary instance, like this:

def Evaluator(IEvaluator):
    def Execute(self, parameters):
        a = parameters['a']
        b = parameters['b']
        c = parameters['c']
        d = parameters['d']
        e = parameters['e']
        return self.Sum(a, b, c, d, e)

    def Sum(self, a, b, c, d, e):
        return a + b + c + d + e

I would like to find a way to programatically assign variable values from the dictionary, something like this:

def Evaluator(IEvaluator):
    def Execute(self, parameters):
        return self.Sum(SetParametersByName(parameters))

    def Sum(Self, a, b, c, d, e):
        return a + b + c + d + e

I know this may not be possible exactly as i wrote, but you get the idea.

Thank you very much,

Esteban.

2 Answers 2

1

This should work:

def Execute(self, parameters):
    return self.Sum(**parameters)

If not, you'll have to convert the .NET Dictionary to a Python dict first (and let me know, so I can file a bug):

def Execute(self, parameters):
    return self.Sum(**dict(parameters))

This feature is often referred to as 'kwargs', I don't believe it has an official name.

Sign up to request clarification or add additional context in comments.

Comments

1
def Execute(self, parameters):
    return self.Sum(**parameters)

will automatically convert .net Dictionary instance into ** python dictionary

Thank you very much.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.