473,398 Members | 2,403 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,398 software developers and data experts.

sys.stdout .>_<.

import os,sys
a = os.fdopen(sys.stdout.fileno(),"w")
b = os.fdopen(sys.stdout.fileno(),"w")
a.write("test1 ")
b.write("test2 ")

stdout result is

test1 test2

but use general file object such as...

a = open("test.txt","w")
b = open("test.txt","w")
a.write("test1")
b.write("test2")

the "test.txt" file content is

test2

how to do this result to sys.stdout
Jul 18 '05 #1
2 1837
It's not possible !

stdout is usually a pipe ... and you cannot go back in a pipe ...
Try with any pipe you should have the same result.

The only way toi achieve this is to assume an ANSI terminal and to use
ANSI codes to go back ("\r" to go at the beginning of the line "^h" to
go back one char)

Leon a écrit :
import os,sys
a = os.fdopen(sys.stdout.fileno(),"w")
b = os.fdopen(sys.stdout.fileno(),"w")
a.write("test1 ")
b.write("test2 ")

stdout result is

test1 test2

but use general file object such as...

a = open("test.txt","w")
b = open("test.txt","w")
a.write("test1")
b.write("test2")

the "test.txt" file content is

test2

how to do this result to sys.stdout

Jul 18 '05 #2
[Format repaired]

Pierre Barbier de Reuille <pi************@cirad.fr> writes:
Leon a écrit :
import os,sys
a = os.fdopen(sys.stdout.fileno(),"w")
b = os.fdopen(sys.stdout.fileno(),"w")
a.write("test1 ")
b.write("test2 ")
stdout result is
test1 test2
but use general file object such as...
a = open("test.txt","w")
b = open("test.txt","w")
a.write("test1")
b.write("test2")
the "test.txt" file content is
test2
how to do this result to sys.stdout It's not possible !


Yup.
stdout is usually a pipe ... and you cannot go back in a pipe ...
Try with any pipe you should have the same result.
Actually, his second example didn't "go back". The two file pointers
started at the beginning of the file. The first write writes "test1"
into the file starting at the beginning. The second write writes
"test2" at the file starting at the beginning, overwriting the results
of the first write.
The only way toi achieve this is to assume an ANSI terminal and to use
ANSI codes to go back ("\r" to go at the beginning of the line "^h" to
go back one char)


The other altnerative is the curses module.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #3

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

Similar topics

8
by: Daniel Hansen | last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and <div>...</div> blocks. When I implement these on a...
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
2
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
5
by: Nathan Sokalski | last post by:
My Web.config file contains the following section to register some of my UserControls: <pages> <controls> <add tagPrefix="NATE" tagName="Banner" src="~/Banner.ascx"/> <add tagPrefix="NATE"...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
7
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what...
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
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
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
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,...
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...
0
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...

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.