Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a Perl module from Python?

Tags:

python

perl

There exists a Perl module that provides the perfect functionality for my Python app. Is there any way for me to utilize it? (it is complicated, it would take me a month to port it)

I don't want to have to spawn a subprocess for every usage, as I need it several hundred thousand times (it is a specific type of data parser).

Thanks for your advice.

EDIT: asked for the module. It's Mail::DeliveryStatus::BounceParser. It matches mail delivery status notifications to a list of strings that may indicate a bounced mail. (it runs the DSN body/headers through a mass of regexes as well as other tests. it's a seriously awesome module.)

like image 793
mikewaters Avatar asked Oct 23 '10 03:10

mikewaters


People also ask

How do I call a Perl module in Python?

Type "pyth. RunPerl. ext;" where "Full Path To File" is the full path filename of your Perl file. This will cause Python to execute the Perl file, then continue down the line with the rest of your Python code.

Can you call Perl from Python?

It is possible to call Perl functions and modules in Python. One way to do that is the PyPerl Module. It is not developed actively any more and for it to work in newer versions, one has to use this version and apply the patches.


2 Answers

I am not sure if this is still active but PyPerl may be of interest to you

  • http://wiki.python.org/moin/PyPerl

Still there should be support for most data parsers in python. It would be good, if you can point to the parser that you are looking at.

Alternatively, you could create a complete process with that perl module and use IPC, socket mechanisms to communicate data and results back and forth from your python and perl processes.

like image 66
pyfunc Avatar answered Oct 23 '22 17:10

pyfunc


I know you can use Python in Perl with Inline::Python but that isn't really your question. Perhaps there is a similar functionality in Python. Perhaps something like perlmodule?

like image 41
Joel Berger Avatar answered Oct 23 '22 18:10

Joel Berger