stdout in pyscripter

178 views
Skip to first unread message

jrh

unread,
Jun 19, 2008, 5:44:05 PM6/19/08
to PyScripter
Hello, I am interested in knowing where stdout (e g printf statements
in c code) ends up in pyscripter.

Example:

A c function, compiled into a python module..

int add(int x, int y) {
int z = x + y;
printf("add will return %d\n",z);
return z;
}

..and a python script using the module:

# file: demo.py
import example
z = example.add(2,3)
print "function add was called from python, and returned %d" % (z)


- Running at the command prompt with python.exe - the c printf comes
directly

C:\Program Files\swigwin-1.3.35\Examples\python\simple>python
demo.py
add will return 5
function add was called from python, and returned 5

- Running in pyscripter using external run - the c printf comes
afterwards

function add was called from python, and returned 5
add will return 5

- Running in pyscripter, internal engine - the c printf does not show

>>>
function add was called from python, and returned 5
>>>
(- but if pyscripter is invoked as "C:\Program Files
\PyScripter>pyscripter > myoutput.txt" I get "add will return 5" into
myoutput.txt once pyscripter is closed.)

- Running in pyscripter remote engine c printf does not show and,
myoutput.txt remains empty.

Does anyone know if there is a way I can get the c printf right into
the interpreter output in pyscripter, just as with python.exe from the
command line?

Thanks alot!

PyScripter

unread,
Jun 20, 2008, 5:29:48 AM6/20/08
to PyScripter
PyScripter and most Python IDEs redirect sys.stdout. Also GUI apps
like PyScripter have no standard output. What you need to do is

PyObject *f = PySys_GetObject("stdout")

and then use

PyFile_WriteString for writing to the sys.stdout.

This is what Python itself is doing and I think this is the best way
for printing from C extensions anyway.
Reply all
Reply to author
Forward
0 new messages