print foo, adds a space to beginning of next line?

Rainy sill at optonline.net
Thu Jun 7 20:18:43 CEST 2001


On Wed, 06 Jun 2001 14:59:04 -0400, George Young <gry at ll.mit.edu> wrote:
> [python 2.1, intel linux]
> def f():
>      print 'what is your name: ',
>      x=sys.stdin.readline()
>      print 'what is your age: ',
>      y=sys.stdin.readline()
> 
> f()
> what is your name: mememe
>  what is your age: 48
> 
> Why does it print a space at the beginning of the second line?
> 
> If I use sys.stdout.write('what is your name: ') instead, it
> works fine.

I think, that's probably an intended effect, as you often need
to separate strings by spaces, so instead of doing
print something + ' ' + something_else you just do
print something, something_else

If you don't want that, you use sys.stdout.write.



-- 
Jupiter and Saturn Oberon Miranda
And Titania Neptune Titan
Stars can frighten
        - Syd



More information about the Python-list mailing list