"stdout" is file object, it open mode is "w"
and it have a close() fuction.....
while it run close(), how to reopen it
because I want to do rewrite it
stdout content update 4 2316
If you want to "rewrite" a "stdout" object, just write a file-like
object and replace sys.stdout !
Then don't care about the old stdout anymore ... it's a pipe and it
won't bother you anymore :)
Another way to do so is the "C" way ... ie. using os.dup2. The advantage
of the "dup2" method is the replacement of the stdout of the whole
program (so, if you use external functions writing in stdout it will
work), but the drawback is you need to have a real file (ie. file, pipe,
....)
Depends on what you want to use :)
Leon a écrit : "stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it
because I want to do rewrite it stdout content update
sorry....
how to replace sys.stdout to file-like object ?
I use os module fdopen() and file object fileno()
stdout = os.fdopen(sys.s tdout.fileno(), "w")
or
stdout = os.fdopen(os.du p(sys.stdout.fi leno()),"w")
it still can't do rewrite, it result is append content
..>_<. Please help me
"Pierre Barbier de Reuille" <pi************ @cirad.fr>
???????:41***** *************** **@news.free.fr ... If you want to "rewrite" a "stdout" object, just write a file-like object and replace sys.stdout !
Then don't care about the old stdout anymore ... it's a pipe and it won't bother you anymore :)
Another way to do so is the "C" way ... ie. using os.dup2. The advantage of the "dup2" method is the replacement of the stdout of the whole program (so, if you use external functions writing in stdout it will work), but the drawback is you need to have a real file (ie. file, pipe, ...)
Depends on what you want to use :)
Leon a écrit : "stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it
because I want to do rewrite it stdout content update
> how to replace sys.stdout to file-like object ?
sys.stdout = open("/this/is/so/simple", "w")
--
Regards,
Diez B. Roggisch
MMmhh ... I'm not sure what you _really_ want to do ???
You want to replace stdout by a custom file-like object ? Because I
don't see what you call "doing rewrite" ... You should give a clear
example of the behaviour you want.
Pierre
Leon a écrit : sorry.... how to replace sys.stdout to file-like object ? I use os module fdopen() and file object fileno() stdout = os.fdopen(sys.s tdout.fileno(), "w") or stdout = os.fdopen(os.du p(sys.stdout.fi leno()),"w")
it still can't do rewrite, it result is append content
.>_<. Please help me
"Pierre Barbier de Reuille" <pi************ @cirad.fr> ???????:41***** *************** **@news.free.fr ...
If you want to "rewrite" a "stdout" object, just write a file-like object and replace sys.stdout !
Then don't care about the old stdout anymore ... it's a pipe and it won't bother you anymore :)
Another way to do so is the "C" way ... ie. using os.dup2. The advantage of the "dup2" method is the replacement of the stdout of the whole program (so, if you use external functions writing in stdout it will work), but the drawback is you need to have a real file (ie. file, pipe, ...)
Depends on what you want to use :)
Leon a écrit :
"stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it
because I want to do rewrite it stdout content update
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gian Mario Tagliaretti |
last post by:
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 ')
|
by: wolfgang haefelinger |
last post by:
Hi,
I wonder whether someone could explain me a bit what's going on here:
import sys
# I'm running Mandrake 1o and Windows XP.
print sys.version
## 2.3.3 (#2, Feb 17 2004, 11:45:40)
|
by: Ron Adam |
last post by:
Can anyone show me an example of of using dis() with a traceback?
Examples of using disassemble_string() and distb() separately if
possible would be nice also.
I'm experimenting with modifying the dis module so that it returns it's
results instead of using 'print' it as it goes. I want to make sure it
works for all the current use cases (or as many as possible), but I
haven't been able to find any examples of using dis with...
|
by: bwaha |
last post by:
I've posted this question to comp.graphics.apps.gnuplot too but given that
this python group may also comprise a lot of gnuplot users, and is far more
active, I've posted this question here too. My apologies to those who read
this twice. I posted to cgag before I decided to post here with a more
meaningful subject.
Anyone had any success getting stdout from gnuplot on an ms windows system
(XP)? I'm trying to read mouse coordinates...
|
by: Henry |
last post by:
I was doing this program for an exercise in a book. The point was to create
a program that would take a numerical grade from a user and convert it to a
letter grade (yeah really easy). I tried to incorporate the while loop to
keep the program running continuously so the user could keep entering grades
to get the letter number, but I had little success and just kept creating
infinite loops. My question is:
How could I modify my program...
| |
by: Christopher Benson-Manica |
last post by:
Given the following:
char s="Hello, world\n!";
Are all the following guaranteed to produce the same output?
printf( "%s", s );
fprintf( stdout, "%s", s );
fwrite( s, sizeof(char), sizeof(s)/sizeof(char) - 1, stdout );
|
by: bruce |
last post by:
hi...
can someone point me to where/how i would go about calling a ruby app from a
python app, and having the python app being able to get a returned value
from the ruby script.
something like
test.py
a = os.exec(testruby.rb)
|
by: Joakim Hove |
last post by:
Hello,
I have written a program in C; this programs uses an external
proprietary library. When calling a certain function in the external
library, the particular function writes a message to stdout. I am not
particularly interested in this message, and would like to silence it
- however I do not know how to do it. (I stdout and stderr my self, so
just redirecting into oblivion is not an option).
An excerpt of the code looks like this:
|
by: Gabriel Genellina |
last post by:
En Tue, 19 Aug 2008 16:48:26 -0300, aditya shukla
<adityashukla1983@gmail.comescribi�:
I don't have a Vista machine to test right now, but I'd expect the above
sequence to hang indefinitely. If you want to execute something, don't
forget the final \n
On XP this works fine:
import subprocess
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |