Adventures in Embedding Python on OS X – Part 1.5

So why part 1.5?  Cause I’m not really starting at the beginning.    I’ll write more later, but here is one way of embedding Python in an Objective-C application, getting access to the app’s objects from Python, and one way to pass ivars over to Python, using a Singleton to manage a pool of objects.

The example is not complete, and not without it’s problems in terms of design, and so on.  There are other ways to do this as well, for example using notifications, or perhaps bindings.   So your mileage may vary, but I hope it helps some people who have been asking about this lately. I have several other Python/ObjC embedding samples that I can share as well, and will endeavor to do so when I have time.

Here’s the source code (Xcode project, OS X 10.5.x, links to system python):
PythonEmbedExample-ObjectPool

One Comment

  1. Jack July 7, 2015

    I know this is pretty old, but thanks for this post. After (quite literally, sadly) weeks spent trying to figure out how to do something like this, I finally came upon this source code and it explained so much that I’d been trying to get a handle on– all I’ve been trying to do is pass some calls from Cocoa to a python-based API and knew it _should_ be possible, but couldn’t figure out how…

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.