我有两个文件,一个常规 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/