sys.stdout .>_<.

L

Leon

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
 
P

Pierre Barbier de Reuille

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 :
 
M

Mike Meyer

[Format repaired]

Pierre Barbier de Reuille said:
Leon a écrit :
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,210
Messages
2,571,091
Members
47,692
Latest member
RolandRose

Latest Threads

Top