There are several possible approaches. The most tempting one is to use py2app to compile a downloadable package from your python-based code, from which you can access the main class using NSBundle . Unfortunately, this precedent did not please py2app developers very much, and I found several errors in 10.5 and 10.6, including a rather nasty memory leak when transferring data from python back to Objective-C. I would not recommend using py2app at this point.
The second approach inverts the attachment. Write a Python cocoa application and load the Objective-C code from the package at startup (even in main ()). If you already have an Objective-C application, this may take a little time. The only drawback that I encounter is that you cannot use GC in Objective-C code, but this is really a universal limitation when working with PyObjC.
Finally, you can create an instance of the python interpreter in your Objective-C code to load Python code. This is obviously more active, but it may be a better option if you already have a large Objective-C code base into which you want to enter your Python code. The main.m file from the Python-Cococa application template in Xcode is a good place to start seeing this in action.
source share