simple Python shell
simple Python shell
- Subject: simple Python shell
- From: email@hidden
- Date: Sat, 9 Aug 2003 03:02:03 +0200
Hi all,
Probably this is very easy! I'm writing a simple shell for the
fantastic Python lang. My problem is : how can i get the output of the
interpreter ? i've got a simple code that works in C [1] but i'm not
able to port it in ObjC!
anyone can help me?
Thanks
Wezzy
[1]
#include "Python.h"
#include <stdio.h>
static PyObject*
mywrite(PyObject* self, PyObject* data)
{
printf("Output is (%s)\n", PyString_AsString(data));
return Py_BuildValue("");
}
static PyMethodDef special_methods[] = {
{"mywrite", mywrite, METH_O, "special 'write' function", },
{0}
};
main(int argc, char **argv)
{
char command[1024];
Py_Initialize();
PyImport_AddModule("special");
Py_InitModule("special", special_methods);
PyRun_SimpleString("\
import sys, special \n\
class X: pass \n\
sys.stdout = X() \n\
sys.stdout.write = special.mywrite \n\
");
while(1) {
printf("> ");
fflush(stdout);
if(!gets(command)) break;
PyRun_SimpleString(command);
}
Py_Finalize();
return 0;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.