Embedding Python in a Cocoa Application

November 4th, 2008 · No Comments · Tutorials

I stumbled upon Ragestorm.net’s great tutorial on Python embedding when I was trying to embed Python in a Cocoa application and redirect standard output / standard error to an NSTextView. Ragestorm’s tutorial is not particularly about Cocoa / Objective-C, but does though solve the problem. Stdout / stderr is simply redirected using a fragment of Python code, which is injected directly after the Python runtime is loaded. It makes use of a couple of C-functions provided by the host application, which connect the Python output to the Cocoa-based NSTextView.

I have uploaded the Python Console Sample Xcode project containing all the code. I think it’s pretty self-explanatory. Have fun!

Tags: ····

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

© 2009 Tobis Lensing. All rights reserved. Powered by Wordpress — based upon Cutline by Chris Pearson. This page reflects the personal opinion of the author and is in no way linked to institutions the author is working or has worked for. For more information, see the disclaimer.