The following code creates a Python class "foo" with a single method __init__. It then gets the class object.
string code = "class foo(object):\n\tdef __init__(self):\n\t\tprint 'hello world'\n"; SourceUnit scriptSource = PythonEngine.CurrentEngine.CreateScriptSourceFromString(code, SourceCodeKind.File); IScriptScope scope = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(scope, scriptSource); object obj2; scope.TryGetVariable("foo", out obj2); PythonType theClass = obj2 as PythonType; I then use PythonType.CreateInstance to create the object. LanguageContext language = LanguageContext.FromEngine( PythonEngine.CurrentEngine); Scope scope2 = new Scope(language); CodeContext context = new CodeContext(scope2, language); object foo = theClass.CreateInstance(context, new object[0]); At this point "foo" contains an object with the Python type "foo". However, the __init__ method was never called. What am I doing wrong? -- Curt Hagenlocher [EMAIL PROTECTED]
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com