Skip Menu |

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

Report information
The Basics
Id: 91559
Status: resolved
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 booleans to Python functions
Date: Sat, 21 Dec 2013 18:02:28 +0100
To: bug-Inline-Python [...] rt.cpan.org
From: Ronald Hecht <ronald.hecht [...] gmx.de>
From Perl I am trying to pass a real Boolean value to Python. I found that this should be supported by the current version. I was trying to create a Python boolean this way: my $true = Inline::Python::Boolean->new(1); But passing this value to Python does not work. Printing received value does not show "True" but <perl object: 'main::Inline::Python::Boolean::'> On the other hand it is possible to get a Boolean from Python and pass it back from Perl to Python. As a workaround, I wrote a small Python function that gives me a Python Boolean to Perl, that can be used for function calls. Strangely the $true value above and the Python returned Boolean show the same correct class (by using 'ref $true') Inline::Python::Boolean. So, How do I correctly pass Python Booleans to perl like a_python_function(Inline::Python::Boolean->new(1));
Fixed by a doc patch. Does the following documentation I just committed help you? Boolean Python supports a Boolean type and two constants False and True. If one of these is passed from Python to Perl, the value is represented by an Inline::Python::Boolean object that uses overload to behave like 1 or undef in boolean context in Perl. When this object is passed back to Python, it is translated back to the False or True constant it originated from. To pass a Boolean value that originated from Perl to Python use the two constants $Inline::Python::Boolean::true and $Inline::Python::Boolean::false if it is important that the value is of type Boolean in Python.
Subject: Re: [rt.cpan.org #91559] How to pass booleans to Python functions
Date: Sat, 21 Dec 2013 18:42:39 +0100
To: bug-Inline-Python [...] rt.cpan.org
From: Ronald Hecht <ronald.hecht [...] gmx.de>
On 12/21/2013 06:30 PM, Stefan Seifert via RT wrote: Show quoted text
> Fixed by a doc patch. Does the following documentation I just committed help you?
Yes, That's great. Just tried it out and it works. Thanks!