这个是百度出来的,写的很明白,没有验证过。
[C#] 纯文本查看 复制代码 using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace Game.download {
public partial class download : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
RunPythonShell(123,"参数2");
}
/// <summary>
/// 调用Python
/// </summary>
private void RunPythonShell(int id,string str) {
ScriptRuntime pyRuntime = Python.CreateRuntime();
//python文件绝对路径
string path = string.Format(@"{0}Test.py", Server.MapPath("./"));
dynamic py = pyRuntime.UseFile(path);
//调用Python 的函数run()
py.run(id.ToString(),str);
}
}
} |