Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to use this with a class but seems to not be working #2

Open
rmarinbe opened this issue Jul 16, 2020 · 4 comments
Open

I want to use this with a class but seems to not be working #2

rmarinbe opened this issue Jul 16, 2020 · 4 comments

Comments

@rmarinbe
Copy link

for example, how do I use the constructor? suppose that you have a class called Person defined in Person.pm
in Perl:
$person = new Person;

in Python

@perlfunc
@perlreq('Person.pm')
def new("person"):    #person should be bless class but here is just a string
    pass  # Empty body
@szwijsen
Copy link

Hi,

I needed that too. But the perlfunc does not handle classes/constructors afaik, only functions.
What I did as workaround was writing a perl wrapper script. That script creates the new instance and contains a function that can pass arguments to the new instance.
Then in your python code you use perlfunc to call that function and pass the required arguments to it (and perlreq to include the wrapper script).
Your case may be different, but this worked for me.

Stefan

@boriel
Copy link
Owner

boriel commented Jul 17, 2020

As @szwijsen commented, this little script is just for functions. The object lives in the Perl space. Your script is executed once, everything is created, the result is serialized upon return, and then everything in the Perl space is destroyed.
You cannot pass objects, only serialize them (i.e. return a JSON string).
A possible solution for this is to use @szwijsen 's approach.

@rmarinbe
Copy link
Author

Hi @boriel and @szwijsen , thanks for the reply! I also thought about @szwijsen solution, unfortunately, as you said, the object lives in Perl space, I am not sure if it keeps the object memory once the function returns? does it? The thing is that I need to keep track of the data in the created object, not just to access its functions.
Also, I realized that the serialization returns only strings, but I have not tried it fully.

What I am trying right now is pyperler, seems to be working with objects, I had initially some problems with the installation because if requires the Perl compilation with multiple threads (I did not know at the time so I have to debug the setup because I am using a very old system).

@boriel
Copy link
Owner

boriel commented Jul 22, 2020

@rmarinbe serialization also returns lists and not sure if it also returns dicts. It uses strings to serialize (encode) the data.
It just executes a perl script, and once the perl script finishes, gets the result.
Other approaches require to keep a Perl interpreter as pyperler so both python and perl intercommunicate.
But I left Perl long ago (10 years ago) so haven't investigate this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants