[Pythonmac-SIG] Using a unix Python with a MacPython Lib tree

Just van Rossum just@letterror.com
Wed, 4 Apr 2001 23:17:19 +0200


Jonathan Wight wrote:

> Yeah. The "assigning a file-like object" approach works fine. So I guess I'm
> just doing a bit of wishful thinking because the way I have to go about is
> kind of annoying:
> 
> 1) Write a C callback function that displays output in my Cocoa NSTextView
> widget.
> 2) Wrap callback in a Python C module.
> 3) Before calling PyRun_String() import sys and replace
> std.stdout/sys.stderr with my C module.
> 
> It would be nice if I could just do a PyXXX_SetStdoutCallback(MyCallback) or
> similar (eliminating steps 2 and 3).
> 
> And I would like to use all the PyRun_InteractiveXXX stuff to provide a real
> Python console interpreter inside my Cocoa application. But I can't (without
> stealing the code and rewriting it) because all the Py_InteractiveXXX
> functions take a FILE * parameter.

I don't know the exact problems you're facing but it sure sounds like you should
do more in Python! There are several console emulators out there, there's even
one in the std lib: code.py. Assigning to sys.stdout is no effort from Python.
All you need is _one_ wrapped C function that sends data to your console, the
rest can all be done in Python.

Just