473,671 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Flushing print()

Is there any way to make Python's print() flush
automatically, similar to...mmm...that other
language's $|=1 ?

If not, how can I flush it manually?
sys.stdout.flus h() didn't seem to work.

_______________ _______________ ____
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
Jul 18 '05 #1
3 9043
gf gf <un************ **@yahoo.com> wrote:
: Is there any way to make Python's print() flush
: automatically, similar to...mmm...that other
: language's $|=1 ?
Hello gf gf,

Yes; you can use the '-u' command line option to Python, which will
turn off stdout/stderr buffering.
: If not, how can I flush it manually? sys.stdout.flus h() didn't
: seem to work.

Hmmmm, that's odd. sys.stdout.flus h() should do it. How are you
testing that stdout isn't flushing as you expect?
Best of wishes to you!
Jul 18 '05 #2
In article <cv***********@ agate.berkeley. edu>,
Daniel Yoo <dy**@hkn.eecs. berkeley.edu> wrote:
gf gf <un************ **@yahoo.com> wrote:

Jul 18 '05 #3
Cameron Laird <cl****@lairds. us> wrote:
gf, remember to write

sys.stdout.flus h()

rather than

sys.stdout.flus h

That's a mistake that catches many.


Many old perl programmers anyway (me included)!

Its also a mistake pychecker catches.

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3846
by: Graham Ashton | last post by:
Hi. I'm having trouble flushing sys.stdout. I've written a small example to illustrate my problem (see below). In short, I expect it to ping "received hello", sleep for 5 seconds and then print "received world". Instead I get nothing for 5 seconds and then both statements pop out at once. As you'll no doubt gather from the example, the problem I'm really trying to solve is sending message back from one process to another via a pipe....
6
4434
by: Farshid Lashkari | last post by:
Hi, My application has python embedded into it. I noticed that when I run any python code the output is buffered and doesn't get flushed until my application exits. To fix this I simply flush sys.stdout and sys.stderr every once in while by using the following code: //Get handle to python stdout file and flush it PyObject *pyStdout = PySys_GetObject("stdout"); if(pyStdout && PyFile_Check(pyStdout)) {
6
5409
by: g pavlov | last post by:
W3C recommendations notwithstanding (see http://w3.org/TR/html401/appendix/notes.html#notes-tables) I can't seem to persuade either of the leading browsers to do true incremental table loading. Neither responds to COL/COLGROUP tags. I have a very large data table which is being generated in J/ECMA/JavaScript dynamically. I want to give the user some top rows while the bottom rows are still loading. Without true incremental table...
5
1940
by: Christopher Benson-Manica | last post by:
Yes, it's me again, with my dear, dear friends std::streambuf and std::ostream... On the bright side, the code compiles. On the gloomy side, I can't seem to get overflow() or xsputn() called... class TWFileBuf : public std::streambuf { private: bool Open( name ) {/* debug printf - does show up */} protected:
3
1774
by: Robert Smith | last post by:
I have some printf statements in my code and they arnt printing out. They only print out with \n on the end. That tells me i need to flush the buffer. But i dont know how. I am using gcc and linux, dont know if that matters
8
3703
by: CJM | last post by:
I have quite a large report, which takes a couple of minutes to run. I'd like to show line-by-line updates as they become available, but since I'm using IE6, Response.Flush() doesnt work. I know that I could break the table up into a series of smaller tables, but I prefer not to do this unless I have to - are there any other alternatives for flushing rows of a table? Thanks
2
14654
by: Fabian Steiner | last post by:
Recently I came across a problem which I still can't solve on my own. Consider this small example: import sys import time time.sleep(3) print sys.stdin.flush() input = raw_input('Your input: ')
3
1315
by: metaperl | last post by:
For this program: def reverse(data): for index in range(len(data)-1, -1, -1): yield data r = reverse("golf") for char in r: print char
0
1948
by: theJade | last post by:
I'm currently running Python 2.5 on Windows 2003. I'm not sure if this is strictly a python issue but I was wondering if anyone has seen and/or knows how to fix this problem. From a linux system using an xterm terminal type, I telnet into the Windows box and execute 'python script.py'. script.py is simply a script that takes in user input using raw_input("prompt: ") and prints what the user inputted onto the screen. However the prompt...
0
8473
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
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8667
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
7428
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
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
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
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
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.