[Tutor] console output that is same in Python 2 and 3

Thierry Tung thierry338 at yahoo.com
Mon Sep 27 18:11:07 CEST 2010


Hello tutor at python.org.

How can I write strings to the console in a way that will give the same result in Python 3 and Python 2?

I tried sys.stdout.write('hello') on Microsoft vista.

with python 3.1.2 
>>>sys.stdout.write('hello')
hello5
>>>

with python 2.7 
>>>sys.stdout.write('hello')
hello>>>

Why is the string length appended to the output with python 3.1.2?

Thanks,
Thierry



      


More information about the Tutor mailing list