Author Keita Kita
Recipients Keita Kita
Date 2015-06-07.09:30:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1433669452.09.0.930876867216.issue24402@psf.upfronthosting.co.za>
In-reply-to
Content
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
----
History
Date User Action Args
2015-06-07 09:30:52Keita Kitasetrecipients: + Keita Kita
2015-06-07 09:30:52Keita Kitasetmessageid: <1433669452.09.0.930876867216.issue24402@psf.upfronthosting.co.za>
2015-06-07 09:30:51Keita Kitalinkissue24402 messages
2015-06-07 09:30:51Keita Kitacreate