[C++-sig] printf from an extension

Andreas Beyer beyer at fli-leibniz.de
Fri Dec 9 17:25:51 CET 2005


Hans Meine wrote:

>On Friday 09 December 2005 01:41, mike cantor wrote:
>  
>
>>the "can print from in here phrase" does not reach python stdout.  Is there
>>something screwy with my environment or is there some trick to this that I
>>don't know.
>>    
>>
>Probably you're fooled by output buffering.  Try appending \n .
>
>  
>
>>static PyObject*
>>helloworld(PyObject* self)
>>{
>>     printf("can print from in here?");
>>     return Py_BuildValue("s", "hello");
>>}
>>    
>>
>
>I'm using cerr/cout all the time.
>
>  
>

It also depends on the context where you call the function. If call from 
idle you won't see anything, because idle does not show the stdout 
output in its shell. If you call from the native python shell you should 
see something, at least after appending '\n'. (Or use fflush().)

Andreas




More information about the Cplusplus-sig mailing list