473,769 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
1 3025
wo*********@yah oo.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3567
by: Minti | last post by:
Is std::cout slower than printf When we call printf e.g. in printf(20 format conversion specifications, 20 arguments); Is it faster than the std::cout << { 20 redirections to the output stream }
16
6545
by: David | last post by:
I have following code. float b; b= 1.234; cout<<hex<<b<<endl; How come it cannot ouput the hex representation of b?
3
6676
by: Jim Langston | last post by:
I have a computer game that has no console. If I want to output something I push a string to the back of a std::vector<std::stringand that gets output and maintained. All is well and good, but what I would like to do is to be able to use ostream's power for this output. I could create my own ostream and check it every cycle or something, but then I would have to pass this ostream or make it global. What I would like to do is have...
8
3470
by: jean.daniel.michaud | last post by:
Hi all, Something I don't get. The code is: // snippet on #include <list> #include <iostream> int main()
19
33438
by: Dancefire | last post by:
Hi, everyone It might be a simple question, but I really don't know the answer. char c = '1'; cout << c; The above code will only output a '1' rather than 0x31; If I use int cast, it can show the number:
5
2604
by: wongjoekmeu | last post by:
Dear All, I have written a small program to read in from console a user string. I wanted to be able to read in a string containing of all sorts of characters untill the user press enter. I have to use in my program the scanf function. The program works fine, but there is one exception. When I don't insert any input, but simply press enter, I want actually to pop up asking the user to enter a valid input. But it seems according to my...
0
216
by: acehreli | last post by:
On Jul 7, 9:56 am, Carsten Fuchs <CarstenFu...@T-Online.dewrote: One option is to leave cout to the others and maintain your own ostream which shares the same output buffer (but not formatting) with cout: #include <iostream> #include <iomanip> using namespace std;
11
6749
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which closes stdout on init because its used to mostly in background processes but I need it for an interactive process. Library cant be changed unfortunately. I tried the following but the C++ version doesn't work, I guess because it only shares the...
58
4854
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better" style and what the pros and cons are (I'm using cout as example, but it really applies to any similar construct): 1) using std::cout;
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.