Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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 # 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]

Replies are listed 'Best First'.
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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015979]
[shmem]: Discipulus: yummy. I like those. Didn't have them for some time now, forgot the name. Should go get some...
[shmem]: Lasy_Aleena: correct, although for clarity I'd use an if() block, not a statement modifier
[shmem]: this allows you to add an else if maintainance makes it neccesary
[Lady_Aleena]: shmem, okeydokey.
[shmem]: ...or logging or debugging or such
[Lady_Aleena]: I'm glad I've sort of learned command line grep so I can find where and how I've used this sub.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-04-27 11:51 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (504 votes). Check out past polls.