I was just playing around with sys.stdout.write()
in a Python console when I noticed that this gives some strange output.
For every write()
call the number of characters written, passed to the function respectively gets append to the output in console.
>>> sys.stdout.write('foo bar')
for example results in
foo bar7
being printed out.
Even passing an empty string results in an output of 0
.
This really only happens in a Python console, but not when executing a file with the same statements. More interestingly it only happens for Python 3, but not for Python 2.
Although this isn't really an issue for me as it only occurs in a console, I really wonder why it behaves like this.
My Python version is 3.5.1 under Ubuntu 15.10.
a = sys.stdout.write('foo')
should reveal this behavior what it actually also does.a
is set to3
in this case, and number isn't append to the output anymore. But I still wonder why this only happens in Python 3. Afaik I also can't find any mention in the doc for this. – Razorbill