473,414 Members | 1,823 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,414 software developers and data experts.

sys.stdout

Hi,

The sys.stdout stream behaves strangely in my
Python2.4 shell:
import sys
sys.stdout.write("AAAA")
sys.stdout.write("BBBB\n") BBBB sys.stdout.write("CCCC\nDDDD") CCCC sys.stdout.flush()

[...nothing...]

Have you ever seen sys.stdout behave like that ?
Any idea what is wrong with my Python2.4 install
or Linux (Mandrake 10.0) system ?

Cheers,

Sébastien

Sep 9 '05 #1
10 3717
Sébastien Boisgérault a écrit :
The sys.stdout stream behaves strangely in my
Python2.4 shell:
>>> import sys
>>> sys.stdout.write("AAAA")
>>> sys.stdout.write("BBBB\n") BBBB >>> sys.stdout.write("CCCC\nDDDD") CCCC >>> sys.stdout.flush()

[...nothing...]


There are two things competing on your stdout: what you explicitely ask
the program to write and the prompt and echo of the interpreter.

Try this:

import sys, time
sys.stdout.write('aaa'); sys.stdout.flush(); time.sleep(2)

Sep 9 '05 #2
Tiissa,

Thanks for your answer. The execution of your example leads to a
'aaa' display during 2 secs, before it is erased by the prompt.

This behavior is standard ? The standard output is not supposed
to *concatenate* the 'aaa' and the '>>>' ?

SB

Sep 9 '05 #3
Sébastien Boisgérault wrote:
Tiissa,

Thanks for your answer. The execution of your example leads to a
'aaa' display during 2 secs, before it is erased by the prompt.

This behavior is standard ? The standard output is not supposed
to *concatenate* the 'aaa' and the '>>>' ?


FWIW:

Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import sys
sys.stdout.write('AAAA') AAAA>>> sys.stdout.write('BBBB\n')
BBBB


--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Sep 9 '05 #4
Sébastien Boisgérault wrote:
Thanks for your answer. The execution of your example leads to a
'aaa' display during 2 secs, before it is erased by the prompt.

This behavior is standard ? The standard output is not supposed
to *concatenate* the 'aaa' and the '>>>' ?


what "python shell" are you using, and what platform are you running
it on? here's what I get on a standard Unix console:
import sys
sys.stdout.write("AAAA") AAAA>>> sys.stdout.write("BBBB\n")
BBBB sys.stdout.write("CCCC\nDDDD")

CCCC
DDDD>>>

</F>

Sep 9 '05 #5

Robert Kern wrote:
Sébastien Boisgérault wrote:
Tiissa,

Thanks for your answer. The execution of your example leads to a
'aaa' display during 2 secs, before it is erased by the prompt.

This behavior is standard ? The standard output is not supposed
to *concatenate* the 'aaa' and the '>>>' ?


FWIW:

Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import sys
sys.stdout.write('AAAA') AAAA>>> sys.stdout.write('BBBB\n')
BBBB


--
Robert Kern
rk***@ucsd.edu


Robert,

I used to have exactly this behavior on my previous platform ...
In the good old days ;)

Do you know if this behavior is mandatory ? Can I *officially*
<wink> state that my Python interpreter is broken ?

I have already tried to recompile and reinstall Python2.4
without any noticeable difference and the Python2.3 rpm
that I have tested exhibits the same behavior ... Doh !
SB

Sep 9 '05 #6
> what "python shell" are you using, and what platform are you running
it on? here's what I get on a standard Unix console:
import sys
sys.stdout.write("AAAA") AAAA>>> sys.stdout.write("BBBB\n")
BBBB sys.stdout.write("CCCC\nDDDD") CCCC
DDDD>>>


btw, what does
sys.stdout.encoding


print ?

</F>

Sep 9 '05 #7

Fredrik Lundh wrote:
Sébastien Boisgérault wrote:
Thanks for your answer. The execution of your example leads to a
'aaa' display during 2 secs, before it is erased by the prompt.

This behavior is standard ? The standard output is not supposed
to *concatenate* the 'aaa' and the '>>>' ?
what "python shell" are you using, and what platform are you running
it on?


The python interpreter is invoked from a bash/konsole session,
inside a KDE env.:

bash$ python
Python 2.4.1 (#4, Sep 8 2005, 19:11:54)
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
here's what I get on a standard Unix console:
import sys
sys.stdout.write("AAAA") AAAA>>> sys.stdout.write("BBBB\n")
BBBB sys.stdout.write("CCCC\nDDDD")

CCCC
DDDD>>>

</F>


Yep. And I hate you for this ;)

Cheers,

SB

Sep 9 '05 #8

Fredrik Lundh a écrit :
what "python shell" are you using, and what platform are you running
it on? here's what I get on a standard Unix console:
> import sys
> sys.stdout.write("AAAA")

AAAA>>> sys.stdout.write("BBBB\n")
BBBB
> sys.stdout.write("CCCC\nDDDD")

CCCC
DDDD>>>


btw, what does
>>> sys.stdout.encoding
print ?

</F>


sys.stdout.encoding

'ISO-8859-15'
SB

Sep 9 '05 #9
On 9 Sep 2005 03:40:58 -0700, Sébastien Boisgérault <Se*******************@gmail.com> wrote:

Fredrik Lundh wrote:
Sébastien Boisgérault wrote:
> Thanks for your answer. The execution of your example leads to a
> 'aaa' display during 2 secs, before it is erased by the prompt.
>
> This behavior is standard ? The standard output is not supposed
> to *concatenate* the 'aaa' and the '>>>' ?


what "python shell" are you using, and what platform are you running
it on?


The python interpreter is invoked from a bash/konsole session,
inside a KDE env.:


So, it's either of these things:
- konsole and its bugs/features
- your $TERM settings
- your readline and its bugs/features
- your ~/.inputrc settings (see the readline man page)

It's hard to say what's right and wrong really, and whose fault it is.
I'm pretty sure it's not Python. What happens if you try bash?

tuva:~> bash
grahn@tuva:~$ echo -n 'foo'
foograhn@tuva:~$

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Sep 9 '05 #10

Jorgen Grahn a écrit :
On 9 Sep 2005 03:40:58 -0700, Sébastien Boisgérault <Se*******************@gmail.com> wrote:

Fredrik Lundh wrote:
Sébastien Boisgérault wrote:

> Thanks for your answer. The execution of your example leads to a
> 'aaa' display during 2 secs, before it is erased by the prompt.
>
> This behavior is standard ? The standard output is not supposed
> to *concatenate* the 'aaa' and the '>>>' ?

what "python shell" are you using, and what platform are you running
it on?
The python interpreter is invoked from a bash/konsole session,
inside a KDE env.:


So, it's either of these things:
- konsole and its bugs/features


Nothing that I could do about it ;)
- your $TERM settings
My xterm settings ?
- your readline and its bugs/features
Uh Uh ... I have disabled my $PYTHONSTARTUP script that
was using some features of the readline module, but
without any success ...
- your ~/.inputrc settings (see the readline man page)
INPUTRC refers to the default Mandrake settings in
etc/inputrc. An old version, 2002. It should be
mostly harmless, right <wink> ...
It's hard to say what's right and wrong really, and whose fault it is.
I'm pretty sure it's not Python. What happens if you try bash?

tuva:~> bash
grahn@tuva:~$ echo -n 'foo'
foograhn@tuva:~$
Bash (into a konsole, same conditions than befor) seems to be ok:

[boisgera@meteor boisgera]$ echo -n 'foo'
foo[boisgera@meteor boisgera]$

:(

Cheers,

SB
/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!


Sep 9 '05 #11

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

Similar topics

6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
4
by: Wes S. | last post by:
How can I redirect and tag sys.stdout values. I tried creating a class module that saved the old stdout and replaced it, but I can't seem to figure out how to do such. Here is what I got... ...
4
by: Leon | last post by:
"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
7
by: Mike | last post by:
I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout,...
10
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally...
9
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
5
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout...
4
by: hg | last post by:
Hi, I have the following ********************* C extention - redir.c #include "Python.h" PyObject * test_redir_test(PyObject *self) {
5
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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
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...
0
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,...
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.