On 8/5/07, Michael Foord <[EMAIL PROTECTED]> wrote:
> Here is a full example:
>
> using System;
> using IronPython.Hosting;
> using IronPython.Runtime.Types;
> using IronPython.Runtime.Operations;
>
> namespace TestPythonConsole
> {
>     class Program
>     {
>         static void Main()
>         {
>             string code = "import
> clr\r\nclr.AddReference('TestPythonConsole')\r\nfrom TestPythonConsole
> import Test\r\nclass X(Test):\r\n     def test(self):\r\n        return
> 'hello'\r\n\r\n";
>             PythonEngine engine = new PythonEngine();
>             EngineModule module = engine.CreateModule();
>             engine.DefaultModule = module;
>             engine.Execute(code);
>             UserType ptype = module.Globals["X"] as UserType;
>             Test obj = Ops.Call(ptype) as Test;
>             Console.WriteLine(obj.test());
>         }
>     }
>
>     public class Test
>     {
>         virtual public string test()
>         {
>             return "goodbye";
>         }
>     }
>
> }
>
> Michael Foord

this is great news.  this is very helpful... thanks.  i assume there
is another Execute method that you can pass in a path to file or take
a file object so we don't have to write the code in a C# string.  what
i would like to do is create the skeleton of C# web services, then
have it call out to python code.  what you just showed here is that
this is definitely possible.  also, i see that your Test was a class
and not a pure interface.  i hope this will work with pure interfaces
too.


bryan
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to