在C#中嵌入IronPython的 [英] Embedding IronPython in C#

查看:116
本文介绍了在C#中嵌入IronPython的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是寻找到IronPython的使用C#和似乎无法找到我所需要的任何伟大的文档。基本上我试图从.py文件的方法调用到C#程序。

I am just looking into using IronPython with C# and cannot seem to find any great documentation for what I need. Basically I am trying to call methods from a .py file into a C# program.

我有这将打开该模块的以下内容:

I have the following which opens the module:

var ipy = Python.CreateRuntime();
var test = ipy.UseFile("C:\\Users\\ktrg317\\Desktop\\Test.py");

不过,我在这里不能确定如何获得访问方法在里面。我所看到的例子使用动态关键字,但是,在工作中我只在C#3.0。

But, I am unsure from here how to get access to the method inside there. The example I have seen uses the dynamic keyword, however, at work I am only on C# 3.0.

感谢。

推荐答案

请参见嵌入上Voidspace站点。

See embedding on the Voidspace site.

一个例子有, IronPython的计算器和计算器
在工作​​从 C#程序调用一个简单的Python前pression评估。

An example there, The IronPython Calculator and the Evaluator works over a simple python expression evaluator called from a C# program.

public string calculate(string input)
{
    try
    {
        ScriptSource source =
            engine.CreateScriptSourceFromString(input,
                SourceCodeKind.Expression);

        object result = source.Execute(scope);
        return result.ToString();
    }
    catch (Exception ex)
    {
        return "Error";
    }
}

这篇关于在C#中嵌入IronPython的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆