473,513 Members | 2,490 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.flush() 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 9026
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.flush() didn't
: seem to work.

Hmmmm, that's odd. sys.stdout.flush() 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.flush()

rather than

sys.stdout.flush

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
3837
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...
6
4427
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...
6
5404
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....
5
1936
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... ...
3
1765
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...
8
3693
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...
2
14561
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...
3
1308
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
1936
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...
0
7260
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,...
0
7539
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...
1
7101
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...
0
7527
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...
0
5686
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,...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1597
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 ...
0
456
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...

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.