Python 和 .NET 集成

发布于 2024-08-12 09:10:39 字数 364 浏览 6 评论 0原文

我目前正在研究 python,因为我真的很喜欢它的文本解析功能和 nltk 库,但传统上我是一名 .Net/C# 程序员。我不认为 IronPython 对我来说是一个集成点,因为我正在使用 NLTK,并且可能需要将该库移植到 CLR。我看了一点 Python for .NET 并想知道这是否是一个好地方开始。有没有办法将 python 类编组到 C# 中?另外,这个解决方案还在使用吗?更好的是,有人这样做过吗?我正在考虑的一件事是使用持久性介质作为中间人(在 Python 中解析,在 MongoDB 中存储,在 .NET 中运行站点)。

I'm currently looking at python because I really like the text parsing capabilities and the nltk library, but traditionally I am a .Net/C# programmer. I don't think IronPython is an integration point for me because I am using NLTK and presumably would need a port of that library to the CLR. I've looked a little at Python for .NET and was wondering if this was a good place to start. Is there a way to marshal a python class into C#? Also, is this solution still being used? Better yet, has anyone done this? One thing I am considering is just using a persistence medium as a go-between (parse in Python, store in MongoDB, and run site in .NET).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沫尐诺 2024-08-19 09:10:39

NLTK 是纯 Python,因此可以轻松地在 IronPython 上运行。搜索发现了这张票 - 只需安装一个IronPython 默认不提供几个额外的 Python 库。

这可能是您集成的最简单方法。否则,您必须将 Python 作为子进程运行(这听起来很复杂),或者将 Python 作为响应您的请求的服务器运行。尽管复杂,但这可能是最具可扩展性的方法。如果您采用这种方式,请考虑使用 Twisted 来简化服务器代码。

但请先尝试一下 IronPython...

NLTK is pure-python and thus can be made to run on IronPython easily. A search turned up this ticket - all one has to do is install a couple of extra Python libraries that don't come by default with IronPython.

This is probably the easiest way for you to integrate. Otherwise, you'll have to either run Python as a subprocess, which sounds complex, or run Python as a server that answers your requests. This is probably the most scalable, though complex, approach. If you go this way, consider Twisted to simplify the server code.

But do try IronPython first...

兔姬 2024-08-19 09:10:39

我不知道为什么你对 IronPython 有问题。您仍然可以在那里使用任何和所有 nltk 调用。

要回答有关将 Python 类移植到 C# 中的问题:尝试将 Python 代码编译为 EXE。这将创建一个 DLL,其中包含所有 Python 类。这是已经存在了一段时间的东西,它在过去对我来说就像一种魅力

I don't know why you have a problem with IronPython. you can still use any and all nltk calls there.

To answer your question about porting a Python class into C#: try compiling your python code into an EXE. This creates a DLL with all your python classes in it. This is something that has been around for a while and it has worked like a charm for me in the past

水波映月 2024-08-19 09:10:39

只是一个想法

如何将 Python 作为服务器运行在后面,并通过套接字从 .NET 连接它?

由于 NLTK 加载需要时间,因此最好提前加载它。

Just an Idea

How about running Python behind as a server, and connect it from .NET with socket?

Since NLTK loading take time and better load it in advance anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文