By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
wo*********@yahoo.com wrote:
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.

--
juergen 'pearly' perlinger
"It's hard to make new errors!"
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.