I have written a bunch of Perl libraries (actually Perl classes) and I want to use some of them in my Python application. Is there a natural way to do this without using SWIG or writing Perl API for Python. I am asking for a similar way of PHP's Perl interface. If there is no such kind of work for Perl in Python. What is the easiest way to use Perl classes in python?
5 Answers
Personally, I would expose the Perl libs as services via XML/RPC or some other such mechanism. That way you can call them from your Python application in a very natural manner.
1 Comment
I haven't tried it, but Inline::Python lets you call Python from Perl.
You should be able to use a thin bit of perl to load your python app and then use the perl python package that comes with I::P to access your Perl objects.
Comments
"What is the easiest way to use Perl classes in python?"
Easiest. Rewrite the Perl into Python and be done with it. Seriously. Just pick one language—that's easiest. Leaving Perl behind is no great loss. Rewriting classes into Python may give you an opportunity to improve them in small ways.
Not so easy. Run the Perl application using Python's subprocess module. That uses the Perl classes in the Perl application without problems. You can easily create pipelines so the Perl gets input from Python and produces output to Python
someApp.py | something.pl | finalStep.py
This has the advantage of breaking your application into three concurrent processes, using up lots of processor resources and running (sometimes) in 1/3 the time.
Everything else is much less easy.
1 Comment
You've just missed a chance for having Python running on the Parrot VM together with Perl. On April 1st, 2009 PEP 401 was published, and one of the Official Acts of the FLUFL read:
- Recognized that C is a 20th century language with almost universal rejection by programmers under the age of 30, the CPython implementation will terminate with the release of Python 2.6.2 and 3.0.2. Thereafter, the reference implementation of Python will target the Parrot virtual machine. Alternative implementations of Python (e.g. Jython, IronPython, and PyPy ) are officially discouraged but tolerated.
4 Comments
Check out PyPerl.
WARNING: PyPerl is currently unmaintained, so don't use it if you require stability.