[IronPython] Creating Python classes in IP2

Paul Turbett sls at iinet.net.au
Sun Mar 30 14:06:18 CEST 2008


Awesome, thanks!

Curt Hagenlocher wrote:
> On Sun, Mar 30, 2008 at 2:59 AM, Paul Turbett <sls at iinet.net.au> wrote:
>   
>> I've looked through the DLR hosting spec, and experimented a bit, but I
>> can't see how to get the same thing working with DLR hosting. So, how do
>> I create instances of python classes from C#?
>>     
>
> This is what works for me:
>
>     ScriptRuntime runtime = ScriptRuntime.Create();
>     ScriptEngine engine = runtime.GetEngine("py");
>
>     // These next two lines are needed if you expect to be able to import System
>     // without manually loading the assembly through Python
>     // runtime.LoadAssembly(typeof(string).Assembly);
>     // runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly);
>
>     // File foo.py contains class Foo
>     ScriptScope scope = runtime.ExecuteFile("foo.py");
>     object theClass;
>     scope.TryGetVariable("Foo", out theClass);
>     object theValue = PythonCalls.Call(theClass);
>
> --
> Curt Hagenlocher
> curt at hagenlocher.org
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080330/7b478801/attachment.html>


More information about the Ironpython-users mailing list