A little more poking suggests that CreateInstance._ctor is really the equivalent of __new__ and not __init__. I changed the code to say
PythonTypeOps.TypeCaller ctor = new PythonTypeOps.TypeCaller(theClass); object foo = ctor.Call(context); and all is now well with the world. On Feb 9, 2008 9:17 AM, Curt Hagenlocher <[EMAIL PROTECTED]> wrote: > 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