Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to access Python member functions from perl

by Anonymous Monk
on Jan 30, 2013 at 06:47 UTC ( #1015979=note: print w/ replies, xml ) Need Help??


in reply to How to access Python member functions from perl

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]


Comment on Re: How to access Python member functions from perl
Select or Download Code
Re^2: How to access Python member functions from perl
by Rahul6990 (Beadle) on Jan 30, 2013 at 07:11 UTC

    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?

Re^2: How to access Python member functions from perl
by PerlRider (Initiate) on Jan 30, 2013 at 07:13 UTC

    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.

Re^2: How to access Python member functions from perl
by PerlRider (Initiate) on Jan 30, 2013 at 07:58 UTC

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-11-26 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls