Python.net doesn't work from python => .NET with named parameters?











up vote
1
down vote

favorite
1












I have a .NET 4.7.2 assembly with a class in it and a method. For example:



public class Foo
{
public void Bar(double duration, string ledPower, string gain, string exposure, string color) { }
}


I want to call it from python 2.7 using pythonnet. This works if the call is:



foo.Bar(1.2, '40', '50', '60', 'blah')


but not if it is using named parameters/kwargs:



foo.Bar(duration=1.2, ledPower='40', gain='50', exposure='60', color='blah')


The error says:




TypeError: No method matches given arguments




This all works with IronPython internally - now I want to run from the CLI using CPython. Any ideas?










share|improve this question
























  • Does it make a difference at all if you change the signature from double to float?
    – Amy
    Nov 9 at 22:16






  • 1




    The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
    – Jeroen Mostert
    Nov 9 at 22:43










  • Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
    – LogicMan
    Nov 12 at 16:10















up vote
1
down vote

favorite
1












I have a .NET 4.7.2 assembly with a class in it and a method. For example:



public class Foo
{
public void Bar(double duration, string ledPower, string gain, string exposure, string color) { }
}


I want to call it from python 2.7 using pythonnet. This works if the call is:



foo.Bar(1.2, '40', '50', '60', 'blah')


but not if it is using named parameters/kwargs:



foo.Bar(duration=1.2, ledPower='40', gain='50', exposure='60', color='blah')


The error says:




TypeError: No method matches given arguments




This all works with IronPython internally - now I want to run from the CLI using CPython. Any ideas?










share|improve this question
























  • Does it make a difference at all if you change the signature from double to float?
    – Amy
    Nov 9 at 22:16






  • 1




    The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
    – Jeroen Mostert
    Nov 9 at 22:43










  • Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
    – LogicMan
    Nov 12 at 16:10













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I have a .NET 4.7.2 assembly with a class in it and a method. For example:



public class Foo
{
public void Bar(double duration, string ledPower, string gain, string exposure, string color) { }
}


I want to call it from python 2.7 using pythonnet. This works if the call is:



foo.Bar(1.2, '40', '50', '60', 'blah')


but not if it is using named parameters/kwargs:



foo.Bar(duration=1.2, ledPower='40', gain='50', exposure='60', color='blah')


The error says:




TypeError: No method matches given arguments




This all works with IronPython internally - now I want to run from the CLI using CPython. Any ideas?










share|improve this question















I have a .NET 4.7.2 assembly with a class in it and a method. For example:



public class Foo
{
public void Bar(double duration, string ledPower, string gain, string exposure, string color) { }
}


I want to call it from python 2.7 using pythonnet. This works if the call is:



foo.Bar(1.2, '40', '50', '60', 'blah')


but not if it is using named parameters/kwargs:



foo.Bar(duration=1.2, ledPower='40', gain='50', exposure='60', color='blah')


The error says:




TypeError: No method matches given arguments




This all works with IronPython internally - now I want to run from the CLI using CPython. Any ideas?







c# python .net python.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 0:42









denfromufa

3,17533098




3,17533098










asked Nov 9 at 22:07









LogicMan

266




266












  • Does it make a difference at all if you change the signature from double to float?
    – Amy
    Nov 9 at 22:16






  • 1




    The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
    – Jeroen Mostert
    Nov 9 at 22:43










  • Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
    – LogicMan
    Nov 12 at 16:10


















  • Does it make a difference at all if you change the signature from double to float?
    – Amy
    Nov 9 at 22:16






  • 1




    The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
    – Jeroen Mostert
    Nov 9 at 22:43










  • Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
    – LogicMan
    Nov 12 at 16:10
















Does it make a difference at all if you change the signature from double to float?
– Amy
Nov 9 at 22:16




Does it make a difference at all if you change the signature from double to float?
– Amy
Nov 9 at 22:16




1




1




The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
– Jeroen Mostert
Nov 9 at 22:43




The code that does this appears to ignore keyword arguments entirely, as far as I can tell. It at least doesn't appear to make any effort to match the keyword arguments with the managed method parameter names. I'm no Python expert, but if the keyword args (dictionary) do not preserve the parameter order, I don't think this code will manage to match.
– Jeroen Mostert
Nov 9 at 22:43












Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
– LogicMan
Nov 12 at 16:10




Thanks for the pointer. I might have to see if I can make a fix to that. In the mean time, I wonder if I can add an overload that will work, perhaps a dict?
– LogicMan
Nov 12 at 16:10

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233874%2fpython-net-doesnt-work-from-python-net-with-named-parameters%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233874%2fpython-net-doesnt-work-from-python-net-with-named-parameters%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation