where the extra space comes from on the stdout

Simon Percivall percivall at gmail.com
Mon Oct 2 19:31:17 EDT 2006


alf wrote:
> Hi,
>
> I can not find out where the extra space comes from. Run following:
>
> import os,sys
> 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
>   Question [Y/[N]]?y
>   Question [Y/[N]]?n
>   Question [Y/[N]]?
>   Question [Y/[N]]?
>
>
> There is a space evrywhere just before Q
>
> Any insight?

You already got the answer, but as for the rest: It's really easier for
you if you use raw_input() for your question/input pair instead.




More information about the Python-list mailing list