Possible Duplicate:
Instantiating a python class in C#
Embedding IronPython in C#可能重复:在C#中实例化python类在C#中嵌入IronPython
I trying this: link
我试着这个:链接
C#:
C#:
private void Form1_Load(object sender, EventArgs e)
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile(@"C:\Users\Admin\Desktop\Test.py");
textBox1.Text = test.Simple();
}
Python:
蟒蛇:
def Simple():
print "Hello from Python"
No error, when I run it, the textbox remain blank. What I doing wrong?
没有错误,当我运行它时,文本框保持空白。我做错了什么?
1 个解决方案
#1
2
Your Simple
function does not return anything, it just prints output to console with print
. Something like return "Hello from Python"
should give you results you want.
您的简单功能不返回任何内容,它只是打印输出到控制台。返回“来自Python的Hello”之类的东西可以给你想要的结果。
Side note: you may be able to intercept console output, but it would probably not what you are interested in.
旁注:您可能能够拦截控制台输出,但它可能不是您感兴趣的。
#1
2
Your Simple
function does not return anything, it just prints output to console with print
. Something like return "Hello from Python"
should give you results you want.
您的简单功能不返回任何内容,它只是打印输出到控制台。返回“来自Python的Hello”之类的东西可以给你想要的结果。
Side note: you may be able to intercept console output, but it would probably not what you are interested in.
旁注:您可能能够拦截控制台输出,但它可能不是您感兴趣的。