By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

sys.stdout

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
> 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

P: n/a

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

P: n/a

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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.