Printing and prompting adds a mysterious extra space

Christoph Haas email at christoph-haas.de
Sat Oct 1 17:44:28 EDT 2005


On Sat, Oct 01, 2005 at 01:17:41PM -0700, mensanator at aol.com wrote:
> Christoph Haas wrote:
> > I'm writing a simple interactive program to maintain a database.
> > The goal was to print "> " at the beginning of the line, wait for
> > user input and then deal with it. Minimal test program:
> >
> > import sys; print ">", ; print sys.stdin.readline()
> >
> > However when I run the program and enter "foobar" it looks like this:
> >
> > ./test.py
> > >foobar
> >  foobar
> > ^----------- where does this space come from?
> 
> Another question you could ask is: why is there NO space after
> the '>'? Have a look at this.
> [...]
> So it looks like the space was sitting in the output buffer.

Yes, probably. But how do I get that buffer flushed? I tried
sys.stdout.flush() after the print statement but it wasn't printed,
either. I probabl need something like...

print "> "+

instead of

print ">",

How could I solve that decently?

 Christoph
-- 
I'm still confused - just on a higher level now.
~
~
".signature" [Modified] 1 line --100%--                1,48         All



More information about the Python-list mailing list