setvbuf() ?? 
Author Message
 setvbuf() ??

I need to print a period on an xterm every few seconds to provide status to the
user, I don't want to force a newline.  How do I turn off line buffering for
standard out?


Mon, 15 Sep 2003 08:24:39 GMT  
 setvbuf() ??

Quote:
> I need to print a period on an xterm every few seconds to provide status
to the
> user, I don't want to force a newline.  How do I turn off line buffering
for
> standard out?

If you're writing the xterm as a file I would have thought the file.flush()
function would do this for you.

regards
 Steve



Mon, 15 Sep 2003 08:57:57 GMT  
 setvbuf() ??

Quote:

> I need to print a period on an xterm every few seconds to provide status to the
> user, I don't want to force a newline.  How do I turn off line buffering for
> standard out?

How about:

import sys

sys.stdout.write(".")
sys.stdout.flush()

Roland Schlenker



Mon, 15 Sep 2003 10:43:29 GMT  
 setvbuf() ??

Quote:
> I need to print a period on an xterm every few seconds to provide status
to the
> user, I don't want to force a newline.  How do I turn off line buffering
for
> standard out?

Running the python interpreter with a -u command line switch turns
buffering off.  That is generally the easiest way, if applicable.

Alex



Mon, 15 Sep 2003 16:52:30 GMT  
 setvbuf() ??
Putting a trailing comma after the print statement eliminates the newline, but
adds a trailing space.  Would periods separated by spaces work?

I would be curious if anyone knows how to eliminate the trailing space.

Bruce

Quote:

> I need to print a period on an xterm every few seconds to provide status to the
> user, I don't want to force a newline.  How do I turn off line buffering for
> standard out?



Mon, 15 Sep 2003 10:09:37 GMT  
 setvbuf() ??

Quote:
> Putting a trailing comma after the print statement eliminates the newline,
but
> adds a trailing space.  Would periods separated by spaces work?

> I would be curious if anyone knows how to eliminate the trailing space.

The simplest way is probably

    import sys
    sys.stdout.write('.')

Alex



Mon, 15 Sep 2003 22:25:23 GMT  
 setvbuf() ??

| I need to print a period on an xterm every few seconds to provide status to the
| user, I don't want to force a newline.  How do I turn off line buffering for
| standard out?

I don't know, but you don't need that anyway - if you don't want buffered
output then don't use an output buffer like stdout!

You can write directly to standard output like this:

   os.write(1, '.')

Unit 1 is by definition standard output;  2 is error and 0 is input.
File objects stdout, stderr and stdin use these same file descriptors
eventually, via C library stdio functions, so when you write directly
to them you just omit a lot of extra stuff you don't want.

If you really want a file object for some reason, stderr normally will
be unbuffered.




Tue, 16 Sep 2003 00:39:54 GMT  
 setvbuf() ??

Quote:
> Putting a trailing comma after the print statement eliminates the newline, but
> adds a trailing space.  Would periods separated by spaces work?

> I would be curious if anyone knows how to eliminate the trailing space.

Either use sys.stdout.write() instead of print, or set sys.stdout.softspace
to 0 after the print command.

--
Remco Gerlich



Tue, 16 Sep 2003 04:24:59 GMT  
 
 [ 8 post ] 

 Relevant Pages 
 

 
Powered by phpBB® Forum Software