[Pythonmac-SIG] Right init method

Jacob Kaplan-Moss jacob at jacobian.org
Mon Jul 4 18:23:29 CEST 2005


Aldo --

PyObjC classes (that is, Python classes that extend ObjC ones, like  
you're trying there) don't use the standard __init__ mechanism (at  
least, not in a useful way).  They do use the standard alloc/init  
mechanism from ObjC, so you're on the right track in your last try:

>     def init(self):
>         super.init(self)
>         NSLog("init")
>         self.speechSynth = NSSpeechSynthetizer.alloc 
> ().initWithVoice_(nil)

The only think you're missing is a "return self" -- ObjC init methods  
always return self, so you have to do the same from PyObjC.

Hope that helps,

Jacob


More information about the Pythonmac-SIG mailing list