Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

How to access Python member functions from perl

by PerlRider (Initiate)
on Jan 30, 2013 at 06:19 UTC ( #1015968=perlquestion: print w/replies, xml ) Need Help??
PerlRider has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have almost no Perl experience but I was wondering if anyone can point me in the right direction. I have a python module with a bunch of member functions and I need to create a Perl wrapper that can call these Python functions. Any help or suggestions would be greatly appreciated!

  • Comment on How to access Python member functions from perl

Replies are listed 'Best First'.
Re: How to access Python member functions from perl
by vinoth.ree (Monsignor) on Jan 30, 2013 at 06:43 UTC

      Hi, Inline::Python module is not inbuilt in perl 5.6 version. Trying to install this module in this version is failed.

        The majority of your posts here relate to problems you have with Perl 5.6. If the solution to all this isn't obvious by now, stop using Perl 5.6, install your own version of a modern perl elsewhere on your system.

        If the current version of Inline::Python doesn't work on your ancient perl, then maybe an older version will. See cpXXXan. The very fact that Inline::Python exists in that CPAN "mirror's" index demonstrates that it has passed its tests at least once on perl 5.6.2.
Re: How to access Python member functions from perl
by Anonymous Monk on Jan 30, 2013 at 06:47 UTC
    You mean something like this ...
    $ cat # Fibonacci numbers module # My Python module def fib(n): # write Fibonacci series up to n a, b = 0, 1 while b < n: print b, a, b = b, a+b def fib2(n): # return Fibonacci series up to n result = [] a, b = 0, 1 while b < n: result.append(b) a, b = b, a+b return result
    ... you need a script like this ...
    $ cat #!/usr/bin/python import fibo fibo.fib(1000) print "\n" print fibo.fib2(100)
    ... and here's a Perl wrapper ...
    $ cat #!/usr/bin/perl print `./`;
    ... see this works like so ...
    $ ./ 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]

      Hi, If I am not wrong. in the above example you have just created a python program and call it inside the Perl script like we call any system command?

      Hi, Thanks for the valuable reply... If the module is having class member functions (let us suppose fib and fib2), and if I want these two member functions be called from two different python scripts where the return value tuple needs to be sent as argument to other function, then how the data variables will be shared.

      I am trying to call Python module from Perl. I created a module in Python which provides two functionalities (Connect and disconnect the PPPOE). While it will be mostly used from within Python, there is a good fraction of legacy idea, which will be calling it from Perl. Google suggest me to do: 1)Provide the functionalities as command line utilities and make system calls 2)Inline::Python I failed to install Inline module in perl 5.6.1 version. So I tried to use the first option. For disconnecting the PPPOE, I need the return value from the Connect function. With this approach is it poossible to get return value from one function to command line? If so please let me know how to do it.

        Another option is to create a web service wrapper around your Python module using something like Flask, and then using an HTTP client like LWP to access it from Perl.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1015968]
Approved by rovf
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-07-24 18:04 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (356 votes). Check out past polls.