SWIG C++ std::cout do not output to interactive interpreter IDLE

W

wongjoekmeu

Dear All,

I have some functions written in C++, which I try to approach from
python using swig. In the C++ functions I use std::cout to print stuff
to output. Everything works fine, but the only problem that I have is
that when I start IDLE and use the functions what std::cout should
print to the "IDLE console" simply does not appear. When I don't use
IDLE but simply double click on the .py script, it works all fine. I
was wondering how I could make sure that std::cout would print also to
IDLE. Thanks a lot in advance for helping to answer my question.

RR
 
J

Juergen Perlinger

Dear All,

I have some functions written in C++, which I try to approach from
python using swig. In the C++ functions I use std::cout to print stuff
to output. Everything works fine, but the only problem that I have is
that when I start IDLE and use the functions what std::cout should
print to the "IDLE console" simply does not appear. When I don't use
IDLE but simply double click on the .py script, it works all fine. I
was wondering how I could make sure that std::cout would print also to
IDLE. Thanks a lot in advance for helping to answer my question.

RR

Hmmmmm... probably tricky. Most GUIs replace 'sys.stdout' by something that
behaves like a Python(!) stream, without actually touching file descriptor
1 (which is the actual process file descriptor for stdout).

From my experience with embedding/extending Python this is going to be a bit
nasty, because you would need to get access to the actual stream object in
Pythons 'sys' module (easy...), wrap this one in C++ to create a C++
ostream descendant that uses an underlying Python stream (here's the
work...) and use it to replace 'cout' (that one's simple after all...).

Are you sure you want to tackle this? I've always tried to avoid it and
lived with the fact that such an extension was only printing something
useful to its output when used as a console application.

I haven't had a deeper look into the BOOST Python bindings, (www.boost.org)
but they have a rather good reputation. Perhaps there is something in it
that takes away most of the burden.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top