http://www.perlmonks.org?node_id=1015968

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!

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 fibo.py # 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 runfib.py #!/usr/bin/python import fibo fibo.fib(1000) print "\n" print fibo.fib2(100)
    ... and here's a Perl wrapper ...
    $ cat runfib.pl #!/usr/bin/perl print `./runfib.py`;
    ... see this works like so ...
    $ ./runfib.pl 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 fibo.py 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.

    A reply falls below the community's threshold of quality. You may see it by logging in.