where the extra space comes from on the stdout

Gabriel G gabrielg_laburando at yahoo.com.ar
Tue Oct 3 01:05:37 CEST 2006

At Saturday 30/9/2006 19:09, Steve Holden wrote:

> > while 1:
> >      print 'Question [Y/[N]]?',
> >      if sys.stdin.readline().strip() in ('Y','y'):
> >          #do something
> >          pass
> >
> > $ python q.py
> > Question [Y/[N]]?y
> >   Question [Y/[N]]?y
> >   Question [Y/[N]]?y
> >
>Yup. When you execute a print statement with a comma at the end it
>doesn't output the space, it simply sets a flag reminding it that there
>should be a space before the next item on the same line. If the next
>character out is a newline then the space flag is reset, but in this
>case the newline was provided by the input, so you get a space at the
>start of the next output.

You could try using
print '\rQuestion?',

Gabriel Genellina
Softlab SRL 

Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 

More information about the Python-list mailing list