Stdout in extensions under IDLE

Joerg Baumann joerg.baumann at stud.informatik.uni-erlangen.de
Thu Oct 5 15:05:22 EDT 2000


You have to use python´s sys.stdout object.
C´s stdout may not be sys.stdout.

e.g.
  
  PyObject * ppp(PyObject *o){
    PyObject *a,*b,*c,*d;
    a,b,c,d=NULL;
    do {
      a=PyImport_AddModule("sys");
      if (a==NULL) break; //Exception
      b=PyModule_GetDict(a);
      if (b==NULL) break; //Exception
      Py_DECREF(a);
      c=PyDict_GetItemString(b,"stdout");
      if (c==NULL) break; //Exception
      Py_DECREF(b);
      d=PyObject_CallMethod(c,"write","O",o); //"O" it´s an oh not zero
      d=PyObject_CallMethod(c,"write","s","\nwas written in C\n");
      if (d==NULL) break; //Exception
      Py_DECREF(c);
      Py_DECREF(d);
      // return None
      Py_INCREF(Py_None);
      return Py_None;
    } while (0);
    // cleanup and signal exception
    Py_XDECREF(a);
    Py_XDECREF(b);
    Py_XDECREF(c);
    Py_XDECREF(d);
    return NULL;
  }



More information about the Python-list mailing list