简体   繁体   English

.NET 和 Python 之间的双向通信

[英]Two way communication between .NET and Python

My main application is a .NET desktop application which relies on some calls to python script for AI.我的主要应用程序是一个 .NET 桌面应用程序,它依赖于对 AI 的 python 脚本的一些调用。 I'd like to know if there are some guidelines/recommandations toward how to best have my python code able to use functions from my .net app.我想知道是否有一些关于如何最好地让我的 python 代码能够使用我的 .net 应用程序中的功能的指南/建议。 Shall I pass functions or shall I have python code also using python.net to callback some functions?我应该传递函数还是让 python 代码也使用 python.net 来回调一些函数?

One example of such pattern would be logging.这种模式的一个例子是日志记录。 I am using Serilog and I would like to reuse my .NET configuration for Python.我正在使用Serilog ,我想为 Python 重用我的 .NET 配置。 Another example would be a function to read some proprietary content where the code exists in .net not in python.另一个例子是 function 来读取一些专有内容,其中代码存在于 .net 中而不是 python 中。

I am currently using Python.NET successfully to call Python functions from my .NET application.我目前正在使用 Python.NET 成功地从我的 .NET 应用程序中调用 Python 函数。

Thank you!谢谢!

I don't think there is a magic bullet for you.我不认为你有灵丹妙药。 Essentially, you are right: if one wants to share logging and other infrastructure they would need to write adapters for one or another language depending on preference.从本质上讲,您是对的:如果想要共享日志记录和其他基础设施,他们将需要根据偏好为一种或另一种语言编写适配器

It would probably be a good idea (for the community) to share those adapters as an open source projects.将这些适配器作为开源项目共享可能是一个好主意(对于社区而言)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM