473,769 Members | 5,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sys.stdout.writ e() question

Hi all,

It is (I hope) a simple question,
I cannot figure out why sys.stdout.writ e() 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.writ e('write ')
time.sleep(3)
sys.stdout.writ e('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.writ e('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 34230
Gian Mario Tagliaretti wrote:
Hi all,

It is (I hope) a simple question,
I cannot figure out why sys.stdout.writ e() 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.writ e('write ')
time.sleep(3)
sys.stdout.writ e('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 Linuxdistributi on 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.writ e('write ')
time.sleep(3)
sys.stdout.writ e('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.writ e('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.flus h() 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.writ e() 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.flus h(). 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
1520
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 mention of such a bug, and stranger yet, other modules that exceed 16384 characters seem to work just fine. In particular, suppose that my module foo.py contains the following as its last line: thing = "goodbye world"
1
2170
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 backslash represented as %2F ?
2
2386
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 copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple lines very well, so I was wondering what is the best way to do this? Maybe there is even a better...
1
1785
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 x minutes have elapsed return the XML from the file and then rewrite the XML file for the next user and reset the clock. If x minutes havent elapsed just return the XML from the file. Do I need to be concerned for any concurrent read/writes or...
22
1601
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
3464
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 here is my situation. I would like to create a program that grabs the source of a displayed webpage, sends it off to another program, then receive the slightly modified source back from that other program, and then reposts the slightly modified...
2
3138
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 character u'\xe9' in position 0: ordinal not in range(128)
3
5326
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 writing to disk. My user claims that performance is much slower on SAN than on local disk. The developer provided me a C++ program that performed a write
2
1112
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 be better to 'open' and 'close' my file on each write cycle? e.g. def writeStuff(content): myFile = open('aFile.txt', 'a+')
0
9589
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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...
1
9994
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
9863
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
8872
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...
1
7409
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.