asp.net C# 执行 Python 带参数, python第三方库

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

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页