Skip Menu |

This queue is for tickets about the Inline-Python CPAN distribution.

Report information
The Basics
Id: 91360
Status: open
Priority: 0/
Queue: Inline-Python

People
Owner: Nobody in particular
Requestors: ronald.hecht [...] gmx.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: How to pass named arguments from Perl to Python
Date: Thu, 12 Dec 2013 12:49:05 +0100
To: bug-Inline-Python [...] rt.cpan.org
From: Ronald Hecht <ronald.hecht [...] gmx.de>
From Perl I am trying to pass arguments by name to the constructor of a Python class. I used the following style: SomePackage::SomePythonClass->new(name1 => value1, name2 => value2); It seems that the constructor is called with 4 arguments instead of 2. I think the argument list looks as follows: 'name1', value1, 'name2', value2. Am I doing it wrong or is it not supported?
Copy and pasting my answer to the same question that I got by email a couple of weeks ago: Named arguments are not supported so far. I could implement a py_call_function_named("package", "function", \@positional, \%named) function, but I'm not sure it's worth the effort. Supporting calling the imported functions with named arguments like in your example seems all but impossible. Inline::Python would have to guess if you want to supply four positional arguments or two named arguments. I could use the same convention as in the the Perl named argument case: my_python_method ( [], {argName1 => val1, argName2 => val2} ); But this would prevent one from calling a Python function with a list and a dictionary as positional parameters. Since Perl itself does not understand the notion of named parameters and everything is just convention, this is one of the very few cases where there's no good mapping between the two languages. Would a py_call_function_named be worth it for you? And just out of curiousity: what are you using Inline::Python for?
Subject: Re: [rt.cpan.org #91360] How to pass named arguments from Perl to Python
Date: Thu, 12 Dec 2013 13:07:49 +0100
To: bug-Inline-Python [...] rt.cpan.org
From: Ronald Hecht <ronald.hecht [...] gmx.de>
Show quoted text
> Supporting calling the imported functions with named arguments like in your example seems all but impossible. Inline::Python would have to guess if you want to supply four positional arguments or two named arguments.
OK. Fully understand. Show quoted text
> Since Perl itself does not understand the notion of named parameters and everything is just convention, this is one of the very few cases where there's no good mapping between the two languages.
I agree. Show quoted text
> Would a py_call_function_named be worth it for you?
I don't think that it is worth the afford. I was just curious, if it is supported the easy way as shown in my example. If not, it's not a problem for me. Show quoted text
> And just out of curiousity: what are you using Inline::Python for?
I'm using it in a Google Play Music plugin for the Logitech media server (aka Squeezebox): https://github.com/hechtus/squeezebox-googlemusic