473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sys.stdout.write() question

Hi all,

It is (I hope) a simple question,
I cannot figure out why sys.stdout.write() doesn't print immediatly the first
text in the small example below, but before it process the code in between
and then print both lines in one time.

#!/usr/bin/env python
import sys, time
sys.stdout.write('write ')
time.sleep(3)
sys.stdout.write('this\n')

if you try to run this, before it will wait 3 seconds and then print "write
this" in one time.

If I put \n here :

sys.stdout.write('write \n')

it work properly but I would like to print the text in one row.

thanks to all
Mario

Jul 18 '05 #1
3 34185
Gian Mario Tagliaretti wrote:
Hi all,

It is (I hope) a simple question,
I cannot figure out why sys.stdout.write() doesn't print immediatly the first
text in the small example below, but before it process the code in between
and then print both lines in one time.

#!/usr/bin/env python
import sys, time
sys.stdout.write('write ')
time.sleep(3)
sys.stdout.write('this\n')

if you try to run this, before it will wait 3 seconds and then print "write
this" in one time.


Apparently the stdout "file" is buffered on your system. Have a look at
file.flush() which could help you out.

Reinhold

--
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix.linux.misc
Jul 18 '05 #2
Gian Mario Tagliaretti wrote:
#!/usr/bin/env python
import sys, time
sys.stdout.write('write ')
time.sleep(3)
sys.stdout.write('this\n')

if you try to run this, before it will wait 3 seconds and then print "write
this" in one time.

If I put \n here :

sys.stdout.write('write \n')

it work properly but I would like to print the text in one row.


It line-buffers the output. If you need to print something that is not 'a
whole line', use sys.stdout.flush() after the ...write()

Jul 18 '05 #3
Gian Mario Tagliaretti wrote:
It is (I hope) a simple question,
I cannot figure out why sys.stdout.write() doesn't print immediatly the first
text in the small example below, but before it process the code in between
and then print both lines in one time.


sys.stdout.flush(). Flush on a file object pushes out all the data
that has been buffered to that point.

-Peter
Jul 18 '05 #4

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

Similar topics

4
by: Lonnie Princehouse | last post by:
I've run into some eccentric behavior... It appears that one of my modules is being cut off at exactly 2^14 characters when I try to import it. Has anyone else encountered this? I can't find any...
1
by: brian | last post by:
how does document.write interpret "" and '' (double quotes and single quotes) what is the significance of &Url (does it signify the current url) colon : is it represented as %3A ? and...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
1
by: David Arden Stevensonn | last post by:
Say I have an XML file on my website that gets read alot (by a c# aspx page) but written to occasionally (also by the same c# aspx page) . Its a simple caching situation based on time. Example: If...
22
by: EMW | last post by:
Hi, When I use Response.Write "something" it is placed at the top op de html document above the <HTML> tag. I need it to be put in the BODY part. How can I do this? rg,
17
by: chris.schwalm | last post by:
I would like to first state that I have searched through the archives and found a lot of related material, but am still new enough to javascript that I can't fit all the pieces together yet. So...
2
by: Brent Lievers | last post by:
Greetings, I have observed the following (python 2.5.1): UTF-8 é Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode...
3
by: golden | last post by:
Hello, I am going to ask a question regarding write and lseek. I will provide code at the end of this, but first some background. I am trying to identify the cause of some latency in...
2
by: Robb Lane (SL name) | last post by:
I have written a script which: - opens a file - does what it needs to do, periodically writing to the file... for a few hours - then closes the file when it's done So my question is: Would it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.