gpt4 book ai didi

C# - 使用 Python 文件中的方法

转载 作者:行者123 更新时间:2023-11-30 21:45:50 25 4
gpt4 key购买 nike

我有两个文件,一个常规 python (.py) 文件和一个 visual studio C# 文件 (.cs)。我想在 python 文件中使用一个返回字符串的函数,并在 C# 文件中使用该字符串。

基本上:

#This is the Python file!
def pythonString():
return "Some String"

//This is the C# file!
namespace VideoLearning
{
string whatever = pythonString(); // This is from the Python file.
}

如何将这两个文件链接在一起?谢谢。

最佳答案

查看 IronPython! :)

好的声明: https://blogs.msdn.microsoft.com/charlie/2009/10/25/running-ironpython-scripts-from-a-c-4-0-program/

希望这对您有所帮助,它很漂亮 ;)

var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
test.pythonString(); //python-function to execute

只需用您的函数替换“pythonString()”(已经这样做了)。

关于C# - 使用 Python 文件中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com