• asp.net 网站调用python执行返回信息Demo


    首先需要引入IronPython,可以通过NuGet搜索获得,基于4.5以上框架集

    using System;
    using IronPython.Hosting;
    using Microsoft.Scripting.Hosting;
    public partial class python : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            RunPythonShell();
        }
        /// <summary>
        /// 调用Python
        /// </summary>
        private void RunPythonShell()
        {
            ScriptRuntime pyRuntime = Python.CreateRuntime();
            //python文件绝对路径
            string path = string.Format(@"{0}1.py", Server.MapPath("./"));
            dynamic py = pyRuntime.UseFile(path);
            //调用Python 的函数run()
            Response.Write(py.show());
        }
    
    }

    python文件代码  1.py

    def show ():
        return "hello world!"
  • 相关阅读:
    第五次博客作业
    第三次博客作业
    个人简介
    实验三
    实验二
    实验一
    《构建之法》心得体会
    第三次博客园作业
    软件测试实验二
    个人简历
  • 原文地址:https://www.cnblogs.com/uxinxin/p/13813889.html
Copyright © 2020-2023  润新知