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);
}
}
}
Test.py
#!/usr/bin/python
# coding=utf-8
import sys
#配置python的绝对路径
sys.path.append(r'C:\Python27')
sys.path.append(r'C:\Python27\lib')
import zipfile
import shutil
import os
def Run(id,param):
return param