Awesome, thanks!

Curt Hagenlocher wrote:
On Sun, Mar 30, 2008 at 2:59 AM, Paul Turbett <[EMAIL PROTECTED]> 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
[EMAIL PROTECTED]
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


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

Reply via email to