我如何使用Python的Perl库?

时间:2022-09-11 02:34:48

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?

我编写了一堆Perl库(实际上是Perl类),我想在我的Python应用程序中使用它们中的一些。有没有一种自然的方法可以在不使用SWIG或为Python编写Perl API的情况下执行此操作。我要求PHP的Perl接口采用类似的方式。如果在Python中没有Perl这样的工作。在python中使用Perl类的最简单方法是什么?

5 个解决方案

#1


8  

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.

就个人而言,我会通过XML / RPC或其他一些此类机制将Perl库作为服务公开。这样,您可以以非常自然的方式从Python应用程序中调用它们。

#2


4  

I haven't tried it, but Inline::Python lets you call Python from Perl.

我没有尝试过,但是Inline :: Python允许你从Perl调用Python。

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.

您应该能够使用一小块perl来加载您的python应用程序,然后使用I :: P附带的perl python包来访问您的Perl对象。

#3


3  

"What is the easiest way to use Perl classes in python?"

“在python中使用Perl类的最简单方法是什么?”

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.

最容易的。将Perl重写为Python并完成它。认真。只选择一种语言 - 这是最简单的。离开Perl并不是很大的损失。将类重写为Python可能会让您有机会以较小的方式改进它们。

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

不那么容易。使用Python的子进程模块运行Perl应用程序。它使用Perl应用程序中的Perl类没有问题。您可以轻松地创建管道,以便Perl从Python获取输入并生成输出到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.

这样做的好处是可以将应用程序分成三个并发进程,占用大量处理器资源并在1/3的时间内运行(有时)。

Everything else is much less easy.

其他一切都不那么容易了。

#4


2  

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:

你刚刚错过了在Perrot VM上运行Python的机会。 2009年4月1日,PEP 401发布,FLUFL的官方法案之一如下:

  • 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.
  • 认识到C是一种20世纪的语言,几乎被30岁以下的程序员拒绝,CPython的实现将随着Python 2.6.2和3.0.2的发布而终止。此后,Python的参考实现将针对Parrot虚拟机。正式劝阻Python的替代实现(例如Jython,IronPython和PyPy)但容忍。

#5


1  

Check out PyPerl.

查看PyPerl。

WARNING: PyPerl is currently unmaintained, so don't use it if you require stability.

警告:PyPerl目前尚未维护,因此如果您需要稳定性,请不要使用它。

#1


8  

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.

就个人而言,我会通过XML / RPC或其他一些此类机制将Perl库作为服务公开。这样,您可以以非常自然的方式从Python应用程序中调用它们。

#2


4  

I haven't tried it, but Inline::Python lets you call Python from Perl.

我没有尝试过,但是Inline :: Python允许你从Perl调用Python。

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.

您应该能够使用一小块perl来加载您的python应用程序,然后使用I :: P附带的perl python包来访问您的Perl对象。

#3


3  

"What is the easiest way to use Perl classes in python?"

“在python中使用Perl类的最简单方法是什么?”

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.

最容易的。将Perl重写为Python并完成它。认真。只选择一种语言 - 这是最简单的。离开Perl并不是很大的损失。将类重写为Python可能会让您有机会以较小的方式改进它们。

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

不那么容易。使用Python的子进程模块运行Perl应用程序。它使用Perl应用程序中的Perl类没有问题。您可以轻松地创建管道,以便Perl从Python获取输入并生成输出到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.

这样做的好处是可以将应用程序分成三个并发进程,占用大量处理器资源并在1/3的时间内运行(有时)。

Everything else is much less easy.

其他一切都不那么容易了。

#4


2  

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:

你刚刚错过了在Perrot VM上运行Python的机会。 2009年4月1日,PEP 401发布,FLUFL的官方法案之一如下:

  • 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.
  • 认识到C是一种20世纪的语言,几乎被30岁以下的程序员拒绝,CPython的实现将随着Python 2.6.2和3.0.2的发布而终止。此后,Python的参考实现将针对Parrot虚拟机。正式劝阻Python的替代实现(例如Jython,IronPython和PyPy)但容忍。

#5


1  

Check out PyPerl.

查看PyPerl。

WARNING: PyPerl is currently unmaintained, so don't use it if you require stability.

警告:PyPerl目前尚未维护,因此如果您需要稳定性,请不要使用它。