C# 在aspx页面中显示python的输出
来自.net新手的问题 你好, 我试图在aspx页面中显示python代码的输出 下面是通过单击按钮1执行的.net c代码C# 在aspx页面中显示python的输出,c#,python,asp.net,visual-studio,ironpython,C#,Python,Asp.net,Visual Studio,Ironpython,来自.net新手的问题 你好, 我试图在aspx页面中显示python代码的输出 下面是通过单击按钮1执行的.net c代码 protected void Button1_Click1(object sender, EventArgs e) { ScriptEngine eng = Python.CreateEngine(); dynamic scope = eng.CreateScope(); eng.ExecuteFile(@"C:\path\hello.py", s
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中 例如: 蟒蛇
a = ""
a += "hello world\n"
a += "==========="
在C中
您的eng.ExecuteFile返回什么?脚本引擎不支持。我应该下载什么dll?此外,如果我有1k行Python代码,那么我必须只把输出放在变量中,而不是变量中的1k行代码…对吗??如果有错误,请更正。@SunnySandeep只需安装nuget包IronPython 2.2.7并添加指令:using IronPython.Hosting;使用Microsoft.Scripting.Hosting;
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();