Strange behavior in Python 3 using sys module

While I tried some things in my Python 3 interpreter (Python 3.4.2 installed via brew), I came across some strange findings that I did not expect:

>>> import sys
>>> sys.stdout.write("foo")
foo3
>>> sys.stderr.write("bar")
3
bar

After experimenting with different lines, I think the number is the length of the inputs that I pass.

I tried this in Python 2.7.8 (does not give numbers in the outputs), and Python 3.4.2 created virtualenv(gives the same result)

Should the conclusion be like this?

+4
source share
2 answers

, . Python 2 File.write() None. Python 3, .

, stdout stderr, , , .

stdout, write "foo", REPL ( PIN- ) .

stderr, , REPL (), .

, , , , , , , , REPL , .

+5

python, - , stdout stderr.

python 3.4. ,

sys.std.write("foo") = > foo3

"foo" stdout. sys.stdout.write, 3. foo3. sys.stdout.write( "foo\n\n" ). .

sys.stderr.write("bar") => 
3
bar

, stdout. 3 . .

+4

All Articles