[Ironpython-users] Calling Python function from C# with **args?

Doug Blank doug.blank at gmail.com
Wed Apr 17 18:44:18 CEST 2013

On Wed, Apr 17, 2013 at 11:42 AM, Jeff Hardy <jdhardy at gmail.com> wrote:
> On Wed, Apr 17, 2013 at 7:00 AM, Doug Blank <doug.blank at gmail.com> wrote:
>> IronPython users,
>> Is there a way to call a Python function or method defined like:
>> def func(**args):
>>     return args
>> from C#?
> PythonCalls.CallWithKeywordArgs should do what you want. If you don't
> have a CodeContext handy you should be able to use
> DefaultContext.Default.

Excellent... yes that worked! I can now call most Python code directly
from our implementation of Scheme (and vice versa, with a CLR wrapper
around our Scheme function calls). Here are a few more details in case
someone needs them.

Thanks for the quick and accurate help!


retval = IronPython.Runtime.Operations.PythonCalls.CallWithKeywordArgs(
 new object [2] {
      new int[2] {1, 1},
      new int[2] {1, 1}
 new string [2] {"input", "output"});

> - Jeff

More information about the Ironpython-users mailing list