一个.net新手的问题
你好,
我正在尝试在 aspx 页面中显示我的 python 代码的输出。
下面是通过单击 Button1 执行的 .net c# 代码。
protected void Button1_Click1(object sender, EventArgs e)
{
ScriptEngine eng = Python.CreateEngine();
dynamic scope = eng.CreateScope();
eng.ExecuteFile(@"C:\path\hello.py", scope);
Label1.Text = //display output in Label1
}
下面是示例 python 脚本。
print "hello"
你能告诉我如何在 Label1.Text 中显示“hello”吗?
也欢迎任何有关在 python 和 asp.net 之间传递数据的信息。
谢谢,
最佳答案
你可以把所有的结果放在变量a中
例子:
python
a = ""
a += "hello world\n"
a += "==========="
在 C# 中
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.ExecuteFile(@"C:\path\hello.py", scope);
var result = scope.GetVariable("a");
Console.WriteLine(result);
Console.ReadLine();
关于c# - 在 aspx 页面中显示 python 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39863217/