Stdout.write() returns an undesired value in QPython

58 views Asked by At

When I use stdout.write() instead of print(), I get an extra return value. How can I get rid of the extra output after a? Thanks for some advice.

>>>from sys import stdout
>>>stdout.write('a''\n')
a
2
1

There are 1 answers

0
Андрей Коровин On BEST ANSWER

write() method always returns the number of characters written. In your case, the method writes a string to a file (the console), so that your console displays string. Then, the method returns the number of characters stored in the file (the console), and outputs the return value to the console. Since the file in which are recorded, and the console - it's the same thing, then you have what you have. Just do not use stdout.write () in console