What do you call the PyObjC code from Objective-C?

Possible duplicate:
Python call from Objective-C

I have been a Python programmer for a long time and Cocoa short time programmer. I'm just starting out with PyObjC and it is really amazing how easy it is to do it. However, I wanted to try using pure ObjC for my controller with PyObjC models. I might like that Python will be Python and Objective-C be Objective-C. I figured it was worth a try, anyway.

Also, I can't figure out or find anything on how to call Python from Objective-C, just the opposite. Can someone point me to any resources? (Maybe this is on the PyObjC website, but I just don't know what I'm looking for?)

Edit: What interests me most at the basic level is the ability to call the Python module and return some of the original ObjC data types.

+4
source share
2 answers

Oops, I think I should look a little more:

Python call from Objective-C

0
source

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.

+3
source

All Articles