New submission from Keita Kita: On Python 3.4, input() does not use wrapped sys.stdout. For example, the following script should print "Wrapped stdout" by print() and input() because sys.stdout is replaced with Writer object.
-------- import io import sys class Writer: def __getattr__(self, name): return getattr(sys.__stdout__, name) def write(self, data): if data != '\n': sys.__stdout__.write('Wrapped stdout\n') def fileno(): raise OSError() sys.stdout = Writer() print('print') input('input') ------ But the script does not print "Wrapped stdout" as prompt of input(). The script prints the following. ----- Wrapped stdout input ---- Although, when sys.stdin is also wrapped, input() will use sys.stdout for prompt. For example, the following script prints "Wrapped stdout" by print() and input(). ---- import io import sys class Writer: def __getattr__(self, name): return getattr(sys.__stdout__, name) def write(self, data): if data != '\n': sys.__stdout__.write('Wrapped stdout\n') def fileno(): raise OSError() class Reader: def __getattr__(self, name): return getattr(sys.__stdin__, name) def read(self, size): return sys.__stdin__.read(size) def fileno(): raise OSError() sys.stdout = Writer() sys.stdin = Reader() print('print') input('input') ---- The script prints the following. ----- Wrapped stdout Wrapped stdout ---- ---------- components: Interpreter Core messages: 244949 nosy: Keita Kita priority: normal severity: normal status: open title: input() uses sys.__stdout__ instead of sys.stdout for prompt type: behavior versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24402> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com