• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
simple Python shell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: simple Python shell
      • From: Ronald Oussoren <email@hidden>
  • Prev by Date: NSDefaults to CFPreference
  • Next by Date: Re: compress/decompress - gzip and gunzip using cocoa
  • Previous by thread: Re: NSDefaults to CFPreference
  • Next by thread: Re: simple Python shell
  • Index(es):
    • Date
    • Thread