Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="2.4.2"
version="2.4.3"
)
9 changes: 6 additions & 3 deletions src/cs50/cs50.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ class Reader:
https://bugs.python.org/issue24402
"""

def __init__(self, f):
self.f = f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's f here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should we rename? Feels a bit magical.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was trying to be consistent with what you have here

self.f = f
. Can be any object (presumably file) passed to the constructor here. We're instantiating a few lines later and passing it sys.stdin, so in the instance that we're using self.f is original sys.stdin.


def __getattr__(self, name):
return getattr(sys.__stdin__, name)
return getattr(self.f, name)

def fileno():
raise OSError()

def read(self, size):
return sys.__stdin__.read(size)
return self.f.read(size)


sys.stderr = flushfile(sys.stderr)
sys.stdin = Reader()
sys.stdin = Reader(sys.stdin)
sys.stdout = flushfile(sys.stdout)


Expand Down