Skip to content

Commit df79b11

Browse files
committed
fixes buffering for input() too
1 parent 9fc40a8 commit df79b11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/cs50/cs50.py

+18
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,25 @@ def write(self, x):
2828
self.f.flush()
2929

3030

31+
class Reader:
32+
"""
33+
Disable buffering for input() as well.
34+
35+
https://bugs.python.org/issue24402
36+
"""
37+
38+
def __getattr__(self, name):
39+
return getattr(sys.__stdin__, name)
40+
41+
def fileno():
42+
raise OSError()
43+
44+
def read(self, size):
45+
return sys.__stdin__.read(size)
46+
47+
3148
sys.stderr = flushfile(sys.stderr)
49+
sys.stdin = Reader()
3250
sys.stdout = flushfile(sys.stdout)
3351

3452

0 commit comments

Comments
 (0)